Sometimes, we want to get the raw value a number input field with JavaScript.
In this article, we’ll look at how to get the raw value a number input field with JavaScript.
How to get the raw value a number input field with JavaScript?
To get the raw value a number input field with JavaScript, we can select the input content and then get the selected contents.
For instance, we write
input.focus();
document.execCommand("SelectAll");
const displayValue = window.getSelection().toString();
to call focus to focus on the input.
Then we call execCommand with 'SelectAll' to select the input box contents.
Finally, we get the selection as a string with window.getSelection().toString().
Conclusion
To get the raw value a number input field with JavaScript, we can select the input content and then get the selected contents.