Snippet: ISO Country List

Last Updated: 14 Aug 2014Hits: 3681
How do I generate a list of countries?

This article features the HTML select/dropdown code snippets to generate a list of countries using the ISO-3166-1 and ISO-3166-2 codes. You can choose between ISO-3166-1 Alpha-2, ISO-3166-1 Alpha-3, ISO-3166 Numeric or the latest ISO-3166-2 codes. Consult the ISO-3166 Wikipedia page for more details.

Some country names have accents and other non-ascii characters, so make sure to set your HTML page's encoding properly. UTF-8 works perfectly for this.

You may copy the code below and paste it into a free format question type. You will need to define the variable and its type (either text or whole number) depending on which code you want to store. In the snippet below, the free format question is named "country" and its variable is "country_code".

Click here to access the PDF with the code attached.

Consult the ISO-3166 Wikipedia page for more details.