Open Source Country Region Selector in JS

I am working on a library/framework for my project. I would like to do a Country selector,

User picks USA it then populates a States box with all states

User picks Canada it then populates another box with all regions for Canada

User picks Mexico it then populates another box with all regions for Mexico

User picks UK it then populates another box with all regions for UK

etc... you get the idea, since it is going to be part of a framework/library I would like to make it ass complete and easy to use. SO I would like to add many different country and region combinations

Also if this is used in a project where the values are saved into a database or file or anywhere as a user setting, then when the page loads and a value is available, it should pre-populate the correct selection boxes and have the correct Country and region selected already.

Now I know Javascript is required, and I am using jQuery so It might be best to use jQuery, and also PHP.

Some questions...

On a personal project, I would probably store all the country and region combinations in a MySQL database however since I want to have this be more of a drop in solution, would it be best to store a file containing ever Country option in a PHP array and then have each set of regions in a separate file as an array.

So the United States would have a separate file that would contain a PHP array of the 50 states, Canada would have a file with all it's different staes/regions etc.. Or is there a better way? OR should I go ahead and just store all this in MySQL or SQLite and provide the proper tables with the code

2) Based off tutorials and stuff I think I can figure out how to make a Region/State selection box populate based off the Country that is selected from another selection box however, if a user have previously selected United States and New York, how would I go about making sure the first box is selected United States and the second box has loaded the file/contents for United States regions/states and then selected the proper states in that list

3) Do you know of anything that exist like this already to help me more or if you would like to contribute anything even getting me in the right direction will help and be greatly appreciated



Google for javascript country state dropdown and you'll find lots of solutions. The first one at already seems pretty reasonable. It stores all the data in the JavaScript code—after all, there are not that many combinations. For countries where it lacks state/region information, the user can enter an arbitrary region.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.