Categories
JavaScript Answers

How to get the raw value a number input field with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *