Skip to main content

Populate a country select

Your form may capture country with a <select> rather than a free text <input> - for example a checkout that stores the ISO-3 country code ("GBR", "IRL", "FRA") against the order.

Point an outputFields country attribute at the <select> and Address Finder selects the matching option for you. It matches the retrieved value against each option's value first, then falls back to the option's visible text, so you don't need a callback.

Map the attribute whose values line up with your option values:

  • country_iso for 3 letter ISO codes ("GBR")
  • country_iso_2 for 2 letter ISO codes ("GB")
  • country for the full country name ("United Kingdom")

Live Demo

The country <select> below uses 3 letter ISO codes as its option values, so country_iso is mapped to it. Search for a UK address and the United Kingdom option is selected automatically.

Loading...