...

View Full Version : multiple select box



SeeIT Solutions
06-14-2005, 05:12 AM
What does a select box (multiple selections allowed) post when a form is submitted?

is it an array? Would something like this code work?



<?php
for ($i = 0;$i < count($_POST['select']);$i++) {
echo $_POST['select'][$i];
}
?>

delinear
06-14-2005, 09:18 AM
It will create an array but only if you use [] brackets in the field name, otherwise you just get the last selected value.

<form action="<?php echo basename($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data" name="form1">
<select name="select[]" size="3" size="1" multiple>
<option value="value1">Option1</option>
<option value="value2">Option2</option>
<option value="value3">Option3</option>
</select>
<input type="submit" name="submit" value="submit" />
</form>

<?php
if($_POST) {
for ($i = 0;$i < count($_POST['select']);$i++) {
echo $_POST['select'][$i] . '<br />';
}
}
?>

SeeIT Solutions
06-14-2005, 09:36 AM
k thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum