Skip to main content

Multi-page Form

You can have the user enter their postcode and open the address form in a new page by saving the user's input in localStorage.

This simulates a user entering a postcode when the Postcode Lookup API is initialised.

Postcode Page

 
localStorage.clear();
const postcode = document.getElementById("postcode");
const btn = document.getElementById("btn-postcode");
btn.addEventListener("click", function () {
localStorage.setItem("postcode", postcode.value);
});

Form Page

 
const pl = PostcodeLookup.setup({
onLoaded: () => {
pl.input.value = localStorage.getItem("postcode");
pl.button.click();
},
context: "#context",
apiKey: "ak_test",
outputFields: {
line_1: "#first_line",
line_2: "#second_line",
line_3: "#third_line",
post_town: "#post_town",
postcode: "#postcode"
},
});

Live Demo

Loading...