a2567429
a2567429

Reputation: 11

Get the selected item from dropdown menu

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

Answers (1)

Bart Friederichs
Bart Friederichs

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

Related Questions