Using $_POST to get select option value from HTML

Felicia Tan picture Felicia Tan · Jun 17, 2013 · Viewed 725.4k times · Source

I use select as below:

<select name="taskOption">
    <option>First</option>
    <option>Second</option>
    <option>Third</option>
</select>

How do I get the value from the select option and store it into a variable for future use, in PHP?

Answer

Praveen Kumar Purushothaman picture Praveen Kumar Purushothaman · Jun 17, 2013

Use this way:

$selectOption = $_POST['taskOption'];

But it is always better to give values to your <option> tags.

<select name="taskOption">
  <option value="1">First</option>
  <option value="2">Second</option>
  <option value="3">Third</option>
</select>