StealThis .dev

Form — Dependent / cascading selects

Two cascading dropdown chains built in vanilla JS over a fictional data set. A Country to State/Region to City rail repopulates and resets every descendant the moment a parent changes, keeps children disabled with clear placeholders until their parent is chosen, and shows a brief loading state as options arrive. A second Category to Subcategory pair mirrors the pattern. Real required validation focuses the first empty menu, and a confirmation panel summarizes the picks. Fully keyboard-operable with aria-live status.

Open in Lab
html css vanilla-js
Targets: JS HTML

Code

Dependent / cascading selects

A shipping form with two dependency chains. The first is a classic Country to State/Region to City cascade over a fictional world (Atlantis, Novaria, Verdantia, Zephyria). Choosing a country populates the region menu and unlocks it; choosing a region populates and unlocks the cities. A small breadcrumb rail above the fields shows exactly where the dependency stands, marking each step active or done. A second Category to Subcategory pair sits below, following the same rules on a separate data set.

Every child menu starts disabled with a placeholder like “Pick a country first,” so the dependency is legible before you touch anything. Changing any parent resets and repopulates its descendants from scratch, clears their values, and re-locks the ones further down the chain. New options arrive after a brief simulated load with a spinner in the field, and focus moves to the newly unlocked menu so keyboard users stay in flow.

Submitting runs a real required-field pass: empty menus get a red border, aria-invalid, and a specific helper message, and focus jumps to the first menu that still needs an answer. A valid submit shows a short loading state and then a confirmation panel that lists the resolved country, region, city, category, and subcategory in plain language, with a “Start over” action that fully resets both chains. Status changes are announced through an aria-live toast.