Page 1 of 1

Unknown amount of checkboxes to check

Posted: Sun Jun 21, 2009 12:19 am
by Loki
Ok, I have a script that has to generate a form, which could have any number of checkboxes, from 1 to idfk. I want to know how I could easilly check which checkboxes are set to "on", and get their ID, when the form is submitted.

Re: Unknown amount of checkboxes to check

Posted: Sun Jun 21, 2009 12:49 am
by requinix
Use arrays.

Code: Select all

<input type="checkbox" name="checkbox[1]">
<input type="checkbox" name="checkbox[2]">
<input type="checkbox" name="checkbox[3]">

Code: Select all

$checkboxes = array_keys($_POST["checkbox"]);
PS: to see which ones were unchecked, figure out what checkboxes were available then "subtract" the ones that were selected.