Reputation: 11
what is the best way to get the selected item from dropdown menu?
My dropdown menu is generated inside while loop if that matters :)
P.s. before you down-vote...I tried a couple of techniques I found on google and on this website.
Here is example of my dropdown menu:
<select id="select1">
<?php
$id = 0;
while ($row = mysql_fetch_row($result)) {
echo "<option value=$id>$row[0]</option>";
$id++;
}
?>
</select>
Upvotes: 0
Views: 2027
Reputation: 33491
Just give it a name
:
<select id="select1" name="myselect">
<?php
$id = 0;
while ($row = mysql_fetch_row($result)) {
echo "<option value=\"$id\">{$row[0]}</option>";
$id++;
}
?>
</select>
Then, when posted, you have the value available in $_REQUEST['myselect']
.
Upvotes: 1