How to make an html drop-down list with countries using javascript

Recently, I was developing a registration form and found myself needing an html drop-down list of countries. Having to write all the <option> tags for about 204 countries is unacceptable, so I scraped them and decided to wrap it all up in a javascript function and share it with the rest of you, who might need it. My countries source was Wikipedia, so if I missed something feel free to add to the list!




The usage is simple. The function is bound by the id of the element where you want the countries dropdown to be injected in. Example:

You can download the code for this how-to in

About Pavel Petrov 2 Articles |  17 How-tos
Pavel is a senior developer for the last 7 years, with extended interest in Linux administration, WordPress and Symfony.