I've learned something from a lot of javascript hacking...
Using [] in element names usually means headache 😉
If you have your checkboxes generated as:
<input name="mycheckboxes[]".... CHECKED>
Then you cannot access the array like you normally would do.
The trick is to access it by name. Like this:
document.forms[0].elemtents['mycheckboxes[]']
This function toggles the selected checkboxes and can easily be modified to fit your needs.
An example follows:
<script language = "javascript">
function toggle( hForm, sName )
{
/ Obtain "handle" to the checkboxes using name /
var hCheckboxes = hForm.elements[ sName ];
/* Indexpointer of the checkboxes */
var iElementIndex = 0;
/* For each element of array, invert (is that the english word??) its status */
for( var iElementIndex=0; iElementIndex<hCheckboxes.length; iElementIndex++ )
{
hCheckboxes[ iElementIndex ].checked = !hCheckboxes[ iElementIndex ].checked;
}
}
</script>
...
...
<form name="test">
<input type = "checkbox" name = "mycheckboxes[]" value="1"><br>
<input type = "checkbox" name = "mycheckboxes[]" value="2"><br>
<input type = "checkbox" name = "mycheckboxes[]" value="3"><br>
<input type = "checkbox" name = "mycheckboxes[]" value="4"><br>
<input type = "checkbox" name = "mycheckboxes[]" value="5"><br>
<input type = "checkbox" name = "mycheckboxes[]" value="6"><br>
<input type = "checkbox" name = "mycheckboxes[]" value="7"><br>
<p>
<input type = "button" value = "toggle" onClick = "toggle( this.form, 'mycheckboxes[]' );">
</form>