I need to get all(Selected and unselected) the values of a multiple select box through POST. How can I do the trick?
Asked
Active
Viewed 9,192 times
1 Answers
3
Create a select tag like this
<select name="data[]" multiple="multiple" >
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
</select>
You can get the selected values:
foreach ($_GET['data'] as $selected) {
echo $selected."\n";
}
You can not get the unselected values.

Rishi Jasapara
- 638
- 9
- 33

PiTheNumber
- 22,828
- 17
- 107
- 180
-
I have done the trick with some Javascript magic and now able to get all the values including selected and unselected. – Tausif Khan Dec 02 '11 at 12:54
-
1The scenario was that I need to have two select box user selects the value from first box and it will go to the second box. that's why i needed to select all the values of second box – Tausif Khan Dec 02 '11 at 12:56
-
The above code wouldn't work. You are passing each element as `$selected` but printing `$selectedOption` – Rishi Jasapara Mar 18 '15 at 07:36