Country State City Drop Down List
General
This is a simple international country, state, and city drop down list that automatically repopulates the state section based on the country selected, and automatically repopulates the city section based on the state selected. All of this is done without reloading the page. This script could also be used in other formats, e.g., automobiles: type/make/model; or books: publisher/author/title.
Notes
- Created by: Michael J. Damato
- Web Site: http://developing.damato.net/
- Posted: July 18, 2007
Format for State lists
- states['Country1'] = new Array('State1','State2','State3');
- states['Country2'] = new Array('State1','State2','State3');
Format for City lists
- cities['Country1'] = new Array();
- cities['Country1']['State1'] = new Array('City1','City 2');
- cities['Country1']['State2'] = new Array('City1','City 2');
- cities['Country2'] = new Array();
- cities['Country2']['State1'] = new Array('City1','City 2');
- cities['Country2']['State2'] = new Array('City1','City 2');
Source Code
Paste this source code into the designated areas.
External file
Paste this code into an external JavaScript file named: countryStateCity.js
Head
Paste this code into the HEAD section of your HTML document.
Body
Paste this code into the BODY section of your HTML document


Leave a Response
(20 comments)hi.. i have also implemented the same code for multiple states and respective cities,its working but the problem is while storing in database it is storing array's index value please help me.... :(
No. You would need to a server-side script, along with a database.
Do you have this for all the countries/states/cities in the world?
Your question is beyond the scope of these comments. You will need to post it over on [a href="http://www.webdeveloper.com/forum/forumdisplay.php?f=3"]the JavaScript forum[/a]. Thanks!
It works fine within one fieldset but doesn't for a second fieldset in the same form. What am I doing wrong?