Hello,
I am working with a dynamic list of checkboxes:
<input name="cbxList[]" type="checkbox" id="cbxList[]" value="1">
<input name="cbxList[]" type="checkbox" id="cbxList[]" value="2">
<input name="cbxList[]" type="checkbox" id="cbxList[]" value="3">
...
I am using cbxList[], so that I can threat the checkboxes as an array in PHP.
Until this point everything works.
But I also want to place a "check/uncheck all" button based on Javascript to check/uncheck all checkboxes:
Therefore I am trying to use the following javascript-code
function checkAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
and this code for the button:
<a href="#" onClick="checkAll(document.form_3.cbxList)"><font size="1" face="Arial, Helvetica, sans-serif"><strong>mark
all</strong></font></a><strong><font size="1" face="Arial, Helvetica, sans-serif">
| <a href="#" onClick="uncheckAll(document.form_3.cbxList)">unmark all</a></font></strong>
The JavaScript does not work because I am using "cbxList[]" instead of "cbxList".
Can someone help me to fix this?
Thanks,