Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get dropdown value and text

<select id="animal" name="animal">                      
<option value="0">--Select Animal--</option>
<option value="1">Cat</option>
<option value="2">Dog</option>
<option value="3">Cow</option>
</select>

if($_POST['submit'])
{
$animal=$_POST['animal'];
}

I have a dropdown like this. What I want, I want to get selected value and text in button submit using PHP. I mean if it's selected 1st one. I want to get both 1 and Cat

Please help. thank you.

like image 905
Sasindu H Avatar asked Jul 12 '11 19:07

Sasindu H


1 Answers

Is there a reason you didn't just use this?

<select id="animal" name="animal">                      
  <option value="0">--Select Animal--</option>
  <option value="Cat">Cat</option>
  <option value="Dog">Dog</option>
  <option value="Cow">Cow</option>
</select>

if($_POST['submit'] && $_POST['submit'] != 0)
{
   $animal=$_POST['animal'];
}
like image 127
Swift Avatar answered Sep 28 '22 10:09

Swift