i have a drop down list in my php code. Im trying to get the value to stay selected after the page has been submitted using a submit button ( the form action calls another php script however the code block below is in the same php script as the form). I tried this but it doesn’t do what i needed to. Any suggestions would help.
//getting value from database
$dropDownVal=$row['player'];
////
echo "<td bgcolor=#7FFF00><select name='DropDown".$row['_id']."' >;
<option value=\"1\" if ($dropDownVal==1) selected=\"selected\">Select </option>;
<option value=\"2\" if ($dropDownVal==2) selected=\"selected\">Johnson</option>;
<option value=\"3\"if ($dropDownVal==3) selected=\"selected\">Reed</option>;
<option value=\"4\"if ($dropDownVal==4) selected=\"selected\">Suggs</option>;
<option value=\"5\"if ($dropDownVal==5) selected=\"selected\">Flacco</option>;
<option value=\"6\"if ($dropDownVal==6) selected=\"selected\">Rice</option>;
</select>";
Chris is essentially correct.
If you are submitting this in a form that uses
POSTvariables.Then if you then modified your logic for setting the
$dropDownValto use the$_POSTvariable you should get what you want:If you’re submitting your form via
GET, just change all references of$_POSTto$_GET.Heres the full code for reference in a single page: