Skip to content
Inserts countries and states / provinces in a dropdown list.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src
README.md
bower.json
example.html

README.md

Countries.js

This is a simple JS library for populating dropdowns with countries and states / provinces.

Example

How To Use

To have a country select dropdown and a state / province select dropdown work together, where "country" is the id of your country select and "state" is the id of your state / province select, simply use:

Countries.create("country", "state");

To manually populate a dropdown with a list of countries where "country" is the id of your target select element:

Countries.fillCountries("country");

To manually populate a dropdown with a list of applicable states / provinces for a selected country where "state" is the id of your target select element:

var country = document.getElementById(countrySelectorId);
var value = country.options[country.selectedIndex].value;
Countries.fillStates("state", index);

Example

To see this library in action, checkout the example.html file located at the root of the project's directory.

Something went wrong with that request. Please try again.