Menu

1 / 2

Why a form reset can return to a saved choice instead of the original one

DEV Community: html·UULab·6 days ago
#DuyJuioW
#devto2#devto#dev#commit#newdefault
Long article (1026 words) — no AI summary yet.
Reading 0:00
15s threshold

A shipping form starts with option A. You choose B. If you haven't saved yet, Cancel changes should take you back to A. But after you save B and select A again, the same button should take you back to B. Which value is reset supposed to restore?

A browser reset does not undo the last click. It restores the input to its current default . I ran the same sequence on two forms, changing only one form’s default. The same native reset restored A in one and B in the other.

01 · CSS reads selection; reset reads the default

On a radio input, the HTML checked attribute supplies the default. The :checked selector matches current selection. In JavaScript, input.checked is current state and input.defaultChecked reflects the attribute. Click B when A has the attribute and the attribute can stay on A while CSS matches B.

The WHATWG rules for input state and reset track whether the user has changed the selection. Don’t assume that updating a default also updates a radio the user has already changed.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.