Hello, here's the problem I'm having.
I have a form, with some checkboxes in. I have given them the name like so, so that I can pass the values back in an array.
echo "<input type=\"checkbox\" name=\"myid[]\" value=\"$id\" class=\"check\">";
ok. that works fine. the form will return the boxes that are checked back in an array. I need to do this, because I need to be able to select multiple boxes.
What I want to do now, is make a "checkall" checkbox, that will check all the boxes when clicked.
here's what I have:
echo "<input name=\"allbox\" type=\"checkbox\" onClick=\"this.value=check(this.form.myid[])\" >";
//and the JavaScript:
<script language="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
}
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
}
}
</script>
I just can't get it to work!!! It's because of the [] at the end of my checkbox name. I need this so the values are stored in an array... but it's stuffing up my JavaScript. If I remove them, it works fine. I can click, and all the boxes will be selected. However, I won't be able to return multiple values back to the server in an array.
Does anyone know a solution to this?
Thankyou
-Adam 🙂