Forum Moderators: coopster
Thanks in advance.
With a drop down menu, you need to determine which option was selected and echo it as the 'selected' value. A ternary operator [php.net] is useful here.
For example, say your drop down menu is:
<select name="options">
<option>Option One</option>
<option>Option Two</option>
<option>Option Three</option>
</select>
You need to change your code to this:
<select name="options">
<option<?php echo (($_POST['options']=="Option One")? " selected " : "");?>>Option One</option>
<option<?php echo (($_POST['options']=="Option Two")? " selected " : "");?>>Option Two</option>
<option<?php echo (($_POST['options']=="Option Three")? " selected " : "");?>>Option Three</option>
</select>
Hope that helps.
dc :)
here is what I used.
<select name="searchBy">
<option value="city" <?php echo (($_POST['searchBy']=="City")? " selected " : "");?>>City</option>
<option value="lp" <?php echo (($_POST['searchBy']=="Price")? " selected " : "");?>>Price</option>
<option value="br" <?php echo (($_POST['searchBy']=="Bedrooms")? " selected " : "");?>>Bedrooms</option>
<option value="dom" <?php echo (($_POST['searchBy']=="Days on Market")? " selected " : "");?>>Days on Market</option>
<option value="sf" <?php echo (($_POST['searchBy']=="Square Feet")? " selected " : "");?>>Square Feet</option>
<option value="lpsf" <?php echo (($_POST['searchBy']=="Price per Square Foot")? " selected " : "");?>>Price per Square Foot</option>
</select>
Please tell me what I am doing wrong?
Thanks.
Here is the code for the menu:
<td> <?
$sql="SELECT user_id,last_name,first_name FROM personneldemo WHERE position='sales'ORDER BY last_name";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$user_id=$row["user_id"];
$last_name=$row["last_name"];
$first_name=$row["first_name"];
$name = $last_name.", ".$first_name;
$options.="<OPTION VALUE=\"$id\">".$name;
$options .= (isset($_POST['menu1']))? "selected=\"selected\"" : "";
}
?>
<SELECT NAME="menu1">
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
</td>
Here is the part of the code for the submit page that is supposed to echo this value:
<?
echo <p> Name: $menu1</p>;
?>
menu1 is the <select name=menu> from the drop down. But, I think I actually need to echo the option that is chosen, and I don't know how to do that.
Any help appreciated.
Cori