Solved

Coldfusion autosum checkbox script

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
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…

730 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