View Single Post
  #8 (permalink)  
Old February 7th, 2013, 01:15 AM
comskiesci comskiesci is offline
Registered User
 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default Checkbox in javascript

hi I am new here..And I have a code below which I can solve it



<script type="text/javascript">
function checkTotal() {
document.listForm.total.value = '';
var sum = 0;
for (i=0;i<document.listForm.choice.length;i++) {
if (document.listForm.choice[i].checked) {
sum = sum + parseInt(document.listForm.choice[i].value);
}
}
document.listForm.total.value = sum;
}
</script>

<form name="listForm">
<input type="checkbox" name="choice" value="2" onchange="checkTotal()"/>2<br/>
<input type="checkbox" name="choice" value="5" onchange="checkTotal()"/>5<br/>
<input type="checkbox" name="choice" value="10" onchange="checkTotal()"/>10<br/>
<input type="checkbox" name="choice" value="20" onchange="checkTotal()"/>20<br/>
Total: <input type="text" size="2" name="total" value="0"/>
</form>


----------------------------------
thats the code above to total the value of selected checkbox
my problem is i want that record in value is coming from sql database and when i select some checkboxes it will get the total ...plss help..
Reply With Quote
The Following User Says Thank You to comskiesci For This Useful Post: