Skip to main content

Multi-page Form

You can have the user enter their postcode and open the address form on 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

The first page collects the postcode and stores it in localStorage:

localStorage.clear();
const postcode = document.getElementById("postcode");
const btn = document.getElementById("btn-postcode");
btn.addEventListener("click", function () {
localStorage.setItem("postcode", postcode.value);
});
<form>
<label for="postcode">Type Postcode Below</label>
<input type="text" id="postcode" />
<a href="/form.html">
<button id="btn-postcode">Search Postcode</button>
</a>
<p>
The postcode you search will be available on the next page using
localStorage
</p>
</form>

Form Page

The address form page reads the stored postcode and auto-triggers the lookup on load:

Live Demo

Loading...