Click to See Complete Forum and Search --> : <SELECT> tag


bobby_dummy_022
11-26-2003, 09:36 PM
this is what I have:

<FORM Action="test.php" MULTIPLE>
<SELECT Name="fruits" size="3">
<OPTION value="1">Apple</OPTION>
<OPTION value="2">Orange</OPTION>
<OPTION value="3">Pineapple</OPTION>
<OPTION value="4">Grape</OPTION>
</SELECT>
</FORM>

my problem is, when I submit the form, I only get the value of the last selected item (despite the fact that the user can select multiple options frmo the list).

$_POST["fruits"] = (the last of the selected options)

I need to get the values of all of the selected options. How?

toicontien
11-26-2003, 11:52 PM
I had to play around with this in one of my classes. I believe this is the code we used in HTML:

<FORM Action="test.php">
<SELECT Name="fruits[]" size="3" multiple>
<OPTION value="1">Apple</OPTION>
<OPTION value="2">Orange</OPTION>
<OPTION value="3">Pineapple</OPTION>
<OPTION value="4">Grape</OPTION>
</SELECT>
</FORM>

Adding the "[]" to the end of the SELECT name causes PHP to interpret the values sent from that SELECT as an array:

$fruitArray = $_POST["fruits[]"];

You'll want to post this in the PHP forum to just to make sure.