EternalHour
EternalHour

Reputation: 8631

Dynamic drop down list for different countries, states, geographic locations?

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

Answers (1)

icecub
icecub

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

  1. index.html: index.html
  2. style.css: style.css
  3. country.js: country.js
  4. dbconnect.php: dbconnect.php
  5. get_country.php: get_country.php
  6. get_states.php: get_states.php
  7. get_city.php: get_city.php
  8. get_data.php: get_data.php

Working Example:

  1. Country, State, City selector

Zip Archive Download (DB NOT included!):

  1. selector.zip (currently down)
  2. Virus Total Analysis of above file

I'm working on an updated script due to the popular demands on this question. It will be added soon.

Upvotes: 9

Related Questions