I currently have a series of checkboxes for different items, which when selected modifies a total. The JavaScript code is below.
<script type="text/javascript">
function checkTotal() {
document.listForm.total.value = '';
var sum = 0.00;
for (i=0;i<document.listForm.choice.length;i++) {
if (document.listForm.choice[i].checked) {
sum = sum + parseFloat(document.listForm.choice[i].value);
}
}
document.listForm.total.value = sum.toFixed(2);
}
</script>
This code works fine, but all the checkboxes have the same input name 'choice'. I need to change this so each input name is different such as choice1, choice2, choice3 etc. How do I change the JavaScript to add up all the differently named checkboxes instead of just adding the ones that are called 'choice'.
Would appreciate any help, good HTML and CSS knowledge but very basic JavaScript. Thanks.