I have this code:
<script type="text/javascript">
function showTotal(form, totalEl)
{
var el, els = form.elements;
var sum = 0;
for (var i=0, num=els.length; i<num; ++i){
el = els[i];
if ('text' == el.type){ //&& /SumB/.test(el.name)
sum += +el.value;
}
form.elements[totalEl].value = sum;
}
}
</script>
If I use an alert I get the correct output but it fills the wrong value into “totalEl” You can test this on (fixed) It’s the first block of checkboxes and textboxes!
Does it work if you try
If
totalElis an element of the form, then theform.elements[totalEl].value = sum;line must be outside theforloop, otherwise the value oftotalElitself will be included in the last calculation, resulting in a double sum.