Choose an Australian suburb from a postcode
Add Australian postcode autofill with editable suburb suggestions and state fields.
Working example
HTML + form.jsSet up ParseAPI
Use a public API key restricted to your website. Keep secret keys on your server.
Get an API key ↗Keep the postcode and suburb separate
An Australian postcode can cover several suburbs, so postcode autofill needs a choice as well as a lookup. Connect your suburb input to city and its native datalist to localities. The fields remain part of your own form.
<script src="https://cdn.parseapi.com/v1/form.js?v=58c6b536b80c" data-key="YOUR_PUBLIC_API_KEY" data-parse-version="2.3.0" defer></script>
<form id="place">
<label for="postcode">Postcode</label>
<input id="postcode" name="postcode" type="text" inputmode="numeric" autocomplete="postal-code" maxlength="4" data-parse="postal" data-parse-country="AU" data-parse-ui="none" aria-describedby="status" placeholder="e.g. 2000">
<div class="row">
<div>
<label for="suburb">Suburb</label>
<input id="suburb" name="suburb" type="text" autocomplete="off" list="suburbs" data-parse-from="postcode" data-parse-fill="city" placeholder="Type or choose a suburb" aria-describedby="suburb-hint">
<datalist id="suburbs" data-parse-from="postcode" data-parse-fill="localities"></datalist>
</div>
<div>
<label for="state">State</label>
<input id="state" name="state" type="text" autocomplete="address-level1" data-parse-from="postcode" data-parse-fill="state" placeholder="NSW">
</div>
</div>
<p id="suburb-hint" class="hint">Click the suburb field to see suggestions. You can always type your own.</p>
<p id="status" class="status" role="status">Enter all four postcode digits to look up the area.</p>
</form>The postcode remains text to preserve leading zeroes. data-parse-country="AU" makes Australia explicit, and form.js waits for four digits before requesting a lookup. The include selects API 2.1.0 with data-parse-version, independently of your team's default.
Choose when a postcode covers several suburbs
Try 2000: the suburb field offers several choices and the state fills as NSW. Choosing SYDNEY keeps that suburb with the postcode. Both fields remain editable.
When city has a value, the script fills it. When it is null, the person chooses from localities or types their own suburb. Leave that choice to them even if only one suggestion is shown; the API has not identified it as the primary suburb.
Choosing a suggestion fills any bound city, state, and state_name fields present in your HTML. The input names submit postcode, suburb, and state to your existing backend.
Fields stay editable and pending responses respect manual corrections. A lookup failure leaves manual entry and submission available. Changing the postcode clears generated values and old suggestions. If your own country picker changes data-parse-country, call parseform.scan() immediately.
Use a custom suggestion menu
For your own menu, listen for the bubbling parse event. Its answer contains the unchanged postcode response and selection holds an explicit { city, state, state_name } choice. Call that event's select(index) callback when the person chooses a suggestion. Old callbacks stop working after postcode or country changes. Keep the host's fields editable.
Use the selected place
Keep the postcode, selected suburb, and state together in your address record. Accept the person's corrections and validate the submitted combination on your server. This is a geographic locality choice; it does not verify an individual address or postal delivery.
Complete example
Use the complete implementation as a reference when adding this feature to your app. It includes the validation and failure handling around the calls above.
View and copy the complete source
<!doctype html>
<html lang="en-AU">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Australian postcode and suburb</title>
<style>
:root { color-scheme: light dark; --ink: #172126; --muted: #57656b; --surface: #fff; --line: #b8c5cc; --focus: #177d96; font-family: system-ui, sans-serif; color: var(--ink); background: var(--surface); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ink: #e8eef0; --muted: #a6b4ba; --surface: #151b1e; --line: #50626c; --focus: #72d1e5; } }
:root[data-theme="dark"] { color-scheme: dark; --ink: #e8eef0; --muted: #a6b4ba; --surface: #151b1e; --line: #50626c; --focus: #72d1e5; }
:root[data-theme="light"] { color-scheme: light; }
body { margin: 0; padding: 28px; }
main { max-width: 560px; margin: auto; }
h1 { font-size: 28px; letter-spacing: -.03em; margin: 0 0 12px; }
p { line-height: 1.55; } .intro, .notice, .hint, footer { color: var(--muted); font-size: 14px; }
.notice { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 18px 0 7px; }
input { font: inherit; box-sizing: border-box; padding: 11px 12px; width: 100%; border: 1px solid var(--line); border-radius: 7px; color: inherit; background: var(--surface); }
input:focus { outline: 2px solid var(--focus); outline-offset: 2px; }
.row { display: grid; grid-template-columns: 1fr 110px; gap: 16px; }
.status { min-height: 22px; font-size: 14px; color: var(--muted); }
footer { margin-top: 28px; font-size: 12px; line-height: 1.6; } a { color: var(--focus); }
@media (max-width: 420px) { body { padding: 20px; } .row { grid-template-columns: 1fr; gap: 0; } }
</style>
</head>
<body>
<main>
<h1>Find your suburb.</h1>
<p class="intro">Enter an Australian postcode. Choose a suburb when there are several, or keep your own entry.</p>
<!-- PREVIEW_NOTICE -->
<!-- example:form -->
<script src="https://cdn.parseapi.com/v1/form.js?v=58c6b536b80c" data-key="YOUR_PUBLIC_API_KEY" data-parse-version="2.3.0" defer></script>
<form id="place">
<label for="postcode">Postcode</label>
<input id="postcode" name="postcode" type="text" inputmode="numeric" autocomplete="postal-code" maxlength="4" data-parse="postal" data-parse-country="AU" data-parse-ui="none" aria-describedby="status" placeholder="e.g. 2000">
<div class="row">
<div>
<label for="suburb">Suburb</label>
<input id="suburb" name="suburb" type="text" autocomplete="off" list="suburbs" data-parse-from="postcode" data-parse-fill="city" placeholder="Type or choose a suburb" aria-describedby="suburb-hint">
<datalist id="suburbs" data-parse-from="postcode" data-parse-fill="localities"></datalist>
</div>
<div>
<label for="state">State</label>
<input id="state" name="state" type="text" autocomplete="address-level1" data-parse-from="postcode" data-parse-fill="state" placeholder="NSW">
</div>
</div>
<p id="suburb-hint" class="hint">Click the suburb field to see suggestions. You can always type your own.</p>
<p id="status" class="status" role="status">Enter all four postcode digits to look up the area.</p>
</form>
<!-- /example:form -->
<footer>
Geographic postcode lookup does not confirm a mailing address or delivery.
</footer>
</main>
<script>
const postcode = document.getElementById('postcode');
const status = document.getElementById('status');
postcode.addEventListener('parse', event => {
const detail = event.detail;
if (detail.status === 'checking') status.textContent = 'Finding suburbs…';
else if (detail.selection) status.textContent = detail.selection.city + ', ' + detail.selection.state + ' selected. You can edit these details.';
else if (detail.answer && detail.answer.city) status.textContent = 'Suburb found. Check the details and edit if needed.';
else if (detail.suggestions.length) status.textContent = detail.suggestions.length + ' suburb suggestions. Choose a suburb or type your own.';
else if (detail.status === 'filled') status.textContent = 'No suburb suggestions for this postcode. Enter your suburb manually.';
else if (detail.reason === 'unavailable') status.textContent = 'Lookup unavailable. You can still enter and use your details.';
else status.textContent = 'Enter all four postcode digits to look up the area.';
});
// Demo only: the host application owns submission.
document.getElementById('place').addEventListener('submit', event => event.preventDefault());
</script>
</body>
</html>
Try the complete example on your computer
Replace YOUR_PUBLIC_API_KEY in the HTML with your public key and add localhost to its allowed domains. Serve the download folder over HTTP:
python3 -m http.server 8000Open localhost:8000/australian-postcode-suburbs.html. Add your website's hostname to the key when using the feature there.
For every field and parameter, see Postal API reference.
Build something else
- Autofill city and state from a ZIP code
- Find nearby ZIP codes
- Calculate distance between ZIP codes
- Find an open store nearby
- Build a local weather card