
Originally Posted by
djr33
But how would you check how many?
I already answered that: the length of the array (if it exists) represents the number of checked checkboxes.
PHP Code:
$checkboxCount = isset($_POST['options']) ? count($_POST['options']) : 0;
If the checkboxes don't have a similar array-like control name[1], things become harder. One solution is to list the names in an array, then loop through them, checking if an element exists:
PHP Code:
$checkboxes = array('foo', 'bar' /* ... */);
$checkboxCount = 0;
foreach ($checkboxes as $name) {
if (isset($_POST[$name])) ++$checkboxCount;
}

Originally Posted by
rocg23
I really don't know JS at all, but this will work if I know the variable I am looking for. Is $i my ouput?
If you're doing this server-side - I assume you are due to database interaction - then client-side scripting is useless at this stage.
Mike
[1] As well as naming form controls with a trailing, empty bracket pair, those brackets can contain a value. The array will still be created as before, but rather than having numeric indices, results can be accessed by name. Consider:
HTML Code:
<form action="..." method="post">
<fieldset>
<legend>Personal details</legend>
<label>First name:
<input name="personal[first-name]" type="text" value=""></label>
<label>Last name:
<input name="personal[last-name]" type="text" value=""></label>
</fieldset>
</form>
When submitted, the $_POST superglobal will contain an element named 'personal'. This will be an array with two elements, 'first-name' and 'last-name'.
Bookmarks