electricphp
Programmer
I have a script that looks like this:
and it basically counts the number of checkboxes that are checked on a page.
the checkboxes are generate dynamically and look like this
the problem is that I need them like this, as an array for further processing
but then the script doesn't work anymore.
any suggestions?
Code:
function calcFees(theCheckbox,reset){
var c = 0;
for (var i=0; i < document.forms['form1'].elements[theCheckbox].length; i++){
if (document.forms['form1'].elements[theCheckbox][i].checked){c = c + 1}
}
and it basically counts the number of checkboxes that are checked on a page.
the checkboxes are generate dynamically and look like this
Code:
<input type="checkbox" value="" name="water" onclick="calcFees('water');">
<input type="checkbox" value="" name="water" onclick="calcFees('water');">
<input type="checkbox" value="" name="water" onclick="calcFees('water');">
...
the problem is that I need them like this, as an array for further processing
Code:
<input type="checkbox" value="" name="water[]" onclick="calcFees('water');">
<input type="checkbox" value="" name="water[]" onclick="calcFees('water');">
<input type="checkbox" value="" name="water[]" onclick="calcFees('water');">
...
any suggestions?