Skip to main content

Convert ISO-3 to ISO-2

By default, the Ideal Postcodes API returns country code in ISO-3 format. If your platform takes in ISO-2 codes instead, use the onLoaded callback function to remap the ISO-3 codes to ISO-2.

 
AddressFinder.setup({
apiKey: "ak_test",
outputFields: {
line_1: "#line_1",
line_2: "#line_2",
line_3: "#line_3",
post_town: "#post_town",
postcode: "#postcode"
},
onLoaded: function () {
const dropdown = document.getElementById("countries");
const c = this;
// Add an event listener to listen for changes in the selected option
dropdown.addEventListener("change", function () {
// Get the selected value
const iso_2 = dropdown.value;
// Extract ISO3 if available
const contexts = Object.values(c.options.contexts);
for (const context of contexts) {
if (context.iso_2 === iso_2) {
c.applyContext(context);
break;
}
}
});
}
});

Live Demo

Loading...