Jump to content

States List with Selection


JasonHarper

Recommended Posts

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

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.