Click to See Complete Forum and Search --> : Referring to an Array of Checkboxes


mohsho
01-06-2003, 09:42 PM
I have dynamically defined the following checkboxes using PHP:

<input type="checkbox" name="accommodation_dates[]" value="13">
<input type="checkbox" name="accommodation_dates[]" value="14">
<input type="checkbox" name="accommodation_dates[]" value="15">
<input type="checkbox" name="accommodation_dates[]" value="16">
<input type="checkbox" name="accommodation_dates[]" value="17">

When the form is submitted, I have no problem dealing with the results.

My problem is that I want to determine how many of these checkboxes are checked in a Javascript function.

I refer to the checkboxes as follows:

for(i=0;i<5;i++) {
if (document.reg_form.accommodation_dates[i].checked) {
... do whatever ...
}
}

This works if the checkboxes are defined without the [], but my PHP stuff on submit won't work unless the [] are there.

Any suggestions would be appreciated.

mohsho
01-07-2003, 08:29 AM
Works perfectly.

Thank you so much, Dave.