Reputation: 8631
I am having my users to enter their city, state, and country. But my dilemma is how to manage it dynamically so that I can control what is entered while having correct spelling and formatting.
For instance, I currently have a static drop down for each state.
<select>
<option name="state" value="AL">Alabama</option>
<option name="state" value="AK">Alaska</option>
<option name="state" value="AZ">Arizona</option>
<option name="state" value="AR">Arkansas</option>
<option name="state" value="CA">California</option>
....
</select>
This works fine obviously, but doesn't scale at all if the user is outside the US. It also falls short in regards to different countries and cities. I have thought of using text fields, then saving them in a separate database and using the JQuery autocomplete plugin for generating the list but it doesn't seem like the best way to do it.
Upvotes: 1
Views: 24219
Reputation: 8773
Ok so after several hours I've written an application based on the MySQL world database: MySQL world Setup
The code for the entire application is way to large to put in an answer so I'll provide Pastebin links for each seperate file, aswell as a link to a working example of the script and a download link for the Zip archive.
I'm sure the code can be improved further, but I'll leave that up to you.
Requirements: MySQL world Database / jQuery
Working Example:
Zip Archive Download (DB NOT included!):
I'm working on an updated script due to the popular demands on this question. It will be added soon.
Upvotes: 9