Solved

Coldfusion autosum checkbox script

Posted on 2011-03-22
4
544 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

860 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