I have a dropdown menu that is generated in another file, and I would like to echo the name of item they selected from dropdown menu not the value of it (0,1,2,3…).
Here is code of the dropdown menu that is generated in another file:
<?php
$selectedKey = $_GET['selected_key'];
$query = "SELECT * FROM `1 selected` WHERE Key = '".$selectedKey."'";
$run = mysql_query($query);
$id1 = 0;
while( $row = mysql_fetch_assoc( $run ) ) {
echo "<option value='".$id1."'>".$row['Contract']."</option>";
$id1++;
}
?>
And this is how it looks in index.php:
<select id="text2" name="text2">
</select>
Now after they submit data I want to echo the name of the item they selected, but when I use echo $_REQUEST['text2']; I get number (value) back, but as said I want to get name.
Select box will send only it’s selected value index to the server, not the value that you see. So simply use
$row['Contract']as the value to be sent to the server: