Forum Moderators: open
trying to get my check all function to work
You can/should assign ID's to these elements
<input type="checkbox" name="[]" id="some-unique-id" value="some-value">
Then reference them by document.getElementById('some-unique-id').
OR you can iterate through the form, and get them by form element type.
<input type="checkbox" name="chkson" id="chkson" value="1" onClick="checkBoxes(this.form,1);"> All on
<input type="checkbox" name="chksoff" id="chksoff" value="1" onClick="checkBoxes(this.form,0);"> All off
function checkBoxes(form,onoff) {
var sw = (onoff==1)?true:false;
for (i=0;i<form.elements.length;i++) {
var obj = form.elements[i];
if ((obj.type=='checkbox') && (obj.name != 'chkson') && (obj.name != 'chksoff')) {
obj.checked = sw;
}
}
if (onoff == 1) { form.chksoff.checked = false; }
else { form.chkson.checked = false; }
}
Note that this still references "name" but only if the names are the on/off checks. Also note that any other checkboxes in the form will be affected, so you may want to add ones you don't want affected by this to the "if" conditional that skips the on/off checks.