Menu

Typed vs set from script: a number input gives different answers
📰

Typed vs set from script: a number input gives different answers

DEV Community: html·Kai Mercer·about 11 hours ago
#jyGsHDmo
#devto2#devto#dev#valid#false
Reading 0:00
15s threshold

Last time I tested what a number input accepts. A reader asked for a cleaner split: what happens when the value is typed, versus set from script? This is that test, in one browser.

Setup: Chrome 155, a plain <input type="number" step="any"> . "Typed" means per-character key events sent by a browser automation tool, which is not the same as a person on a keyboard. "Set" means input.value = "..." from script. For each case I read four properties: value , valueAsNumber , validity.badInput and checkValidity() .

String Typed Set from script

1e3 "1e3", 1000, badInput false, valid same

.5 ".5", 0.5, false, valid same

abc "", null, false, valid same

1e "", null, badInput true, invalid "", null, false, valid

- "", null, true, invalid "", null, false, valid

1e400 "", null, true, invalid "", null, false, valid

1,5 "15", 15, false, valid "", null, false, valid

+5 "5", 5, false, valid "", null, false, valid

5.…

Continue reading — create a free account

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