Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get sum for dynamic checkboxes

 
sonali duggi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello every one.

here i have a problem in getting sum for dynamic check boxes..

my requirement is if i select one check box the amount will be added to the total amount field and select other field the total amount will display in amount field..

one thing is all check boxes are getting dynamically..

thanks in advance..
 
K. Tsang
Bartender
Posts: 3526
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AJAX??
 
sonali duggi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no.. i want in java script
 
sonali duggi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i got the solution

follow the below code to solve the problem

function calculate() {
var elems = document.forms['formID'].elements;
var total = 0;
for(var i=0;i<elems.length;i++) {
if (elems[i].checked) {total += +(elems[i].value);}
}
elems['total'].value = total;
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic