Click to See Complete Forum and Search --> : An array of checkboxes


Brendan Nolan
05-12-2003, 02:21 AM
I am writing a PHP application which has a form in it.

The form has a list of results and a checkbox next to each of them.

I found out that if I named the checkbox "checkbox[]" instead of "checkbox" it will store the checked rows in an array in PHP, otherwise it will just overwrite the previous values and store only the last one.

But I want to have a "Check / Uncheck All" button, and I can use

document.forms.some_form.checkbox.checked=true;

and if I have a bunch of checkboxes all named "checkbox" i can use

document.forms.some_form.checkbox[1].checked=true;
document.forms.some_form.checkbox[2].checked=true;
document.forms.some_form.checkbox[3].checked=true;

etc.

But how do I do it if I name my checkbox "checkbox[]" so that I get that nice array in PHP?

I have tried things like

document.forms.some_form.checkbox[][1].checked=true;
and
document.forms.some_form.checkbox\[\][1].checked=true;
and even
document.forms.some_form.checkbox%5B%5D[1].checked=true;
(••• I DID name the checkbox "checkbox%5B%5D" in that one!)

and none of them work!

Please help :)

A1ien51
05-12-2003, 02:30 AM
Off the top of my head:

TheForm=documnt.form[0].elements;

StartCheck=5; //Start Element number of the array
EndCheck=10;//End Element number of the array

for(i=StartCheck;i<=EndCheck;i++){
TheForm[i].checked="true";
}


Eric

Brendan Nolan
05-12-2003, 03:06 AM
Thanks for that, it works fine for what I need to do. But there may be times where an object may be created and because the whole thing is written in PHP it is hard to keep track of which form objects are what number.

Does anyone have a solution for the problem that sitll can referance the objects individually by name - even whith [] in it?


I am in the clear now though, thanks :)