Solved

Coldfusion autosum checkbox script

Posted on 2011-03-22
4
525 Views
Last Modified: 2012-05-11

How do I turn this script into a Coldfusion dynamic output checkbox autosum .

function UpdateCost() {
  var sum = 0;
  var gn, elem;
  for (i=0; i<5; i++) {
    gn = 'game'+i;
    elem = document.getElementById(gn);
    if (elem.checked == true) { sum += Number(elem.value); }
  }
  document.getElementById('totalcost').value = sum.toFixed(2);
}


<input type="checkbox" id='game0' value="9.99"  onclick="UpdateCost()">Game 1 ( 9.99)<br>
<input type="checkbox" id='game1' value="19.99" onclick="UpdateCost()">Game 2 (19.99)<br>
<input type="checkbox" id='game2' value="27.50" onclick="UpdateCost()">Game 3 (27.50)<br>
<input type="checkbox" id='game3' value="45.65" onclick="UpdateCost()">Game 4 (45.65)<br>
<input type="checkbox" id='game4' value="87.20" onclick="UpdateCost()">Game 5 (87.20)<br>
<input type="text" id="totalcost" value="">
0
Comment
Question by:smares32371
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 35194728
Not sure what a "Coldfusion dynamic output checkbox autosum" means.

What do you need javascript to do - that it's not doing now?
0
 

Author Comment

by:smares32371
ID: 35194837
the script works fine because the form id is static and defined for 5 ids. With coldfusion the form id value will be dynamic from a sql output no limit to count of records.
0
 

Author Comment

by:smares32371
ID: 35194862
<table border="0" cellpadding="3" cellspacing="0" width="100%">            
 <cfoutput query="qGetOpenItemsTrans">
  <tr>
   <td><input type="Checkbox">#TRIM(qGetOpenItemsTrans.tranno)#
</td>
 </tr>
</cfoutput>                  
</table>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 35194942
<script>
function UpdateCost() {
  var total = 0;
  var itemCount = document.getElementById('itemCount').value;
  for (var i=1; i<=itemCount; i++) {
    var elem = document.getElementById("trans"+ i);
    if (elem.checked == true) { total += Number(elem.value); }
  }
  document.getElementById('totalcost').value = total.toFixed(2);
}
</script>

<!--- replace #ColumnToSum# with your column value --->
<cfoutput query="qGetOpenItemsTrans">
        <!--- use #currentRow# to name fields trans1, trans2, etc... --->
	<input type="checkbox" id='trans#CurrentRow#' value="#ColumnToSum#"  onclick="UpdateCost()">#transno#<br>
</cfoutput>
<!--- display total cost --->
Total Cost <input type="text" id="totalcost"><hr>

<!--- store total field count --->
<cfoutput>
<input type="hidden" id="itemCount" value="#qGetOpenItemsTrans.recordCount#">
</cfoutput>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now