?
Solved

Coldfusion autosum checkbox script

Posted on 2011-03-22
4
Medium Priority
?
558 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 2000 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses

743 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