1. Home
  2. Computing & Technology
  3. JavaScript

Country Selection Form

When you are creating a form, you often want the person filling out the form to provide an address. Given the international nature of the internet, one thing that you need to capture as part of any address is the Country. The countries in the world are relatively static (barring wars and successions) so a drop down list where the person can select their country rather than typing it is one option to consider. Unfortunately there are quite a lot of countries in the world and finding a relatively complete list may take some time let alone the time required to convert that list into a drop down selection box.

Never fear because I am about to save you the trouble of doing any of that. The following generates the HTML for a dropdown list that allows one of 235 different countries to be selected which is as close as I can get to including all of the countries of the world. All you need to do is to name the drop down list and select which country you want as the default. (If I haven't offered your preferred country as the default you can change the code to get the default you want by selecting Australia and then transferring the ' selected="selected"' code to the option that you want as the default).

Field name:
Default Entry
add null entry default
Australia
Canada
France
Germany
New Zealand
United Kingdom
United States

If you are wondering what the dropdown looks like once inserted into your page, here is a form containing the code with Australia selected as the default.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.