JasonHarper Posted January 25, 2010 Share Posted January 25, 2010 Hello, I need help with what I think is an easy issue. I have a list of all states in a MySQL database. I have a form where the user selects a state from a drop down list and I have that populated with info from the DB. That part is working perfectly. However, when the user returns to that page I'm pre-populating the form with their data. What's happening is that the user's state appears correctly in the pre-filled drop down list, but it appears at the top and then again in the list from the DB. Example: If user's state is Arizona, the drop down list would look something like this: Arizona Alabama Alaska Arizona ... My question is this....how do I make the user's state appear only once in the list and in the correct location (alphabetical order)? Thank you! Jason Quote Link to comment Share on other sites More sharing options...
schilly Posted January 25, 2010 Share Posted January 25, 2010 When you are outputting the the states from the database when creating the menu, check the user's state against each value. If you find a match output selected="selected" in the option tag. You don't need to add an additional option from the user's state. eg. <option value='Arizona' selected='selected'>Arizona</option> Quote Link to comment Share on other sites More sharing options...
JasonHarper Posted January 25, 2010 Author Share Posted January 25, 2010 That worked perfectly - thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.