To get the raw value a number input field with JavaScript, we select the input value and return it.
For instance, we write
input.focus();
document.execCommand("SelectAll");
const displayValue = window.getSelection().toString();
to focus on the input with focus
.
Then we call execCommand
to select everything in the input box.
Finally, we get the selected text with getSelection
and convert it to a string with toString
.