1

I need to get all(Selected and unselected) the values of a multiple select box through POST. How can I do the trick?

defau1t
  • 10,593
  • 2
  • 35
  • 47
Tausif Khan
  • 2,228
  • 9
  • 40
  • 51
  • show the code, have a look on http://stackoverflow.com/questions/2407284/how-to-get-multiple-selected-values-of-select-box-in-php – Haim Evgi Nov 30 '11 at 12:18

1 Answers1

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
  • 1
    The 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