Solved

Coldfusion autosum checkbox script

Posted on 2011-03-22
4
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

728 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