using PHP how can you display the value selected in a drop down list?

  • Thread starter Thread starter djbennett999
  • Start date Start date
D

djbennett999

Guest
If you are using php to dynamically display an html form with error messages, how can you get it to have the option that user has chosen in the drop down list selected in the drop down list rather than it going back to the top item in the drop down list when the form is reloaded?
 
<option selected value="Something">Something</option>

you will have to define the value like

$state="La";

if($state == $state){
echo "<option selected=\"$state\" value=\"$state\">$state</option>";
}
else
{
echo "<option value=\"$state\">$state</option>";
}
}
 
if using a database, order the 'id' number of the select from highest to lowest. (I suggest highest) so you can just make a cookie. When the user selects the option and submits the form, a cookie is saved to that option with a high id value, and ordering the list by highest to lowest will make that option go to the top.
You will need a while() php string to do this.

but, it was incredibly hard to understand you question, please grammar properly.
 
What you have to do is submit the form to its self, where the error check is also carried out, if an error is found, just output the submitted details back to the form using $_GET['FIELD_NAME']

So you would post your data using $_POST['FIELD_NAME']
 
Back
Top