Handling a Multiple Drop Down Box
Hello I have a <select name="dropbox" multiple="multiple" size="2"> in a form. When the user clicks the submit button the method used is POST.
I then handle the information by storing it in a variable.
Code:
$myMultiDropDownBox = $_POST['dropbox'];
I then tried to echo that variable. When multiple options were selected the echo wouldn't work. How do I handle the various items the user may have selected? Is it stored in an array? Hence I must do a loop?
Re: Handling a Multiple Drop Down Box
For PHP, you'll need to declare the select name as an array...
Code:
<select name="dropbox[]" multiple="multiple" size="2">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
...in order to receive an array of the values...
Code:
print_r($_POST['dropbox']);
/* if you selected both options, this prints:
Array
(
[0] => 1
[1] => 2
)
*/
echo $_POST['dropbox'][0]; //echos 1
echo $_POST['dropbox'][1]; //echos 2