Connect country, state and county choices
Load state suggestions from a country, then county suggestions from the selected state in your own form.
Last tested
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 ↗Connect country, state and county
Connect three ordinary dropdowns without hardcoding the state or county lists. Include form.js, mark the country selector, and bind the state select to the returned states. Mark that select with data-parse="state" and bind the county select to its counties response.
<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>
<div class="field">
<label for="country">Country</label>
<select id="country" name="country" data-parse="country" autocomplete="country">
<option value="">Choose a country</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
<option value="GB">United Kingdom</option>
<option value="AU">Australia</option>
<option value="FR">France</option>
</select>
</div>
<div class="field">
<label for="state">State, province, or region</label>
<select id="state" name="state" data-parse="state" data-parse-from="country" data-parse-fill="states" autocomplete="address-level1">
<option value="">Choose a region</option>
</select>
</div>
<div class="field">
<label for="district">County or comparable area</label>
<select id="district" name="district" data-parse-from="state" data-parse-fill="counties">
<option value="">Choose a county</option>
</select>
</div>The five country choices are examples. Replace them with the countries your form accepts, keeping their two-letter codes as option values.
Select a country
Choosing a country loads its subdivisions. The region dropdown shows their names, such as Colorado. Selecting a name sets the field's value to its subdivision code, such as CO. The browser supplies the menu and keyboard navigation.
Changing countries clears the previous region and county choices. A late lookup for the previous country cannot replace the current list. Keep the empty placeholder option so the form can show that no choice has been made yet.
The list can contain states, provinces, territories, or other subdivisions. Choose the geographic level your application needs.
Select a state
Choosing a state code loads its counties or districts through /state/{code}/counties?country=XX. The state field reads its country from the existing country-to-states connection. For a standalone state field, set an explicit data-parse-country="US" instead. The requests use the ordinary included API; no Deep option is needed.
County option values are stable codes, with names as labels. The current lists cover the US, France and Great Britain. Other countries can still load their states; leave the county blank where a list is unavailable.
Changing a state clears its previous county choices and selected value. Changing the country also cancels the previous county lookup. A late response cannot fill choices for a different country or state. Missing results and lookup failures leave the placeholder in place and do not add a submission block. Selecting the country or state again retries the lookup.
The two bindings connect the fields: data-parse-from="country" data-parse-fill="states" fills the state select, and data-parse-from="state" data-parse-fill="counties" fills the county select. Form.js creates each option with the API's name as its visible text and the code as its value.
Submit the country alongside the state and county. Each select's name supplies the backend field: country, state and county. Keep all three in your address or location record and validate the submitted combination on your server. If your application also needs unlisted locations, provide a separate, clearly labeled manual-entry path.
Build directly with the Country API when you need custom dropdown behavior or country details.
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">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Connect country, state and county choices</title>
<style>
:root { color-scheme: light dark; --bg: #fff; --ink: #152029; --muted: #5e6b75; --line: #d9e2e7; --field: #f6f9fa; --accent: #007c91; --error: #b42335; }
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) { --bg: #0b1015; --ink: #eff7fa; --muted: #94a6b2; --line: #2c3942; --field: #121b23; --accent: #67e8f9; --error: #fda4af; }
}
:root[data-theme="dark"] { color-scheme: dark; --bg: #0b1015; --ink: #eff7fa; --muted: #94a6b2; --line: #2c3942; --field: #121b23; --accent: #67e8f9; --error: #fda4af; }
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; padding: 24px; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, sans-serif; }
main { max-width: 540px; margin: 0 auto; }
label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
input, select { display: block; width: 100%; min-width: 0; padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink); font: inherit; }
input::placeholder { color: var(--muted); }
/* Keep native selection; size the closed control consistently in Safari. */
select:not([multiple]):where(:not([size]), [size="0"], [size="1"]) {
-webkit-appearance: none;
appearance: none;
padding-right: 40px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%2371717a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 12px center;
background-size: 16px;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field + .field { margin-top: 18px; }
/* Your form owns these styles. form.js adds semantic markup and states. */
input[data-parse-status="invalid"], input[data-parse-status="disposable"] { border-color: var(--error); }
.parse-hint { margin: 6px 0 0; color: var(--muted); font-size: .875em; line-height: 1.4; overflow-wrap: anywhere; }
.parse-hint[data-parse-status="invalid"], .parse-hint[data-parse-status="disposable"] { color: var(--error); }
@media (max-width: 380px) { body { padding: 18px; } }
</style>
</head>
<body>
<main>
<!-- 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>
<div class="field">
<label for="country">Country</label>
<select id="country" name="country" data-parse="country" autocomplete="country">
<option value="">Choose a country</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
<option value="GB">United Kingdom</option>
<option value="AU">Australia</option>
<option value="FR">France</option>
</select>
</div>
<div class="field">
<label for="state">State, province, or region</label>
<select id="state" name="state" data-parse="state" data-parse-from="country" data-parse-fill="states" autocomplete="address-level1">
<option value="">Choose a region</option>
</select>
</div>
<div class="field">
<label for="district">County or comparable area</label>
<select id="district" name="district" data-parse-from="state" data-parse-fill="counties">
<option value="">Choose a county</option>
</select>
</div>
<!-- /example:form -->
</main>
</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/country-state-dropdown.html. Add your website's hostname to the key when using the feature there.
For every field and parameter, see Country API reference and State API reference.