How can i get the "real" value of an <input type="number">
field?
I have an input
box, and i'm using newer HTML5 input type number
:
<input id="edQuantity" type="number">
This is mostly supported in Chrome 29:
What i now need is the ability to read the "raw" value the user has entered in the input box. If the user has entered a number:
then edQuantity.value = 4
, and all is well.
But if the user enters invalid text, i want to color the input-box red:
Unfortunately, for a type="number"
input box, if the value in the text-box is not a number then value
returns an empty string:
edQuantity.value = "" (String);
(in Chrome 29 at least)
How can i get the "raw" value of an <input type="number">
control?
i tried looking through Chrome's list of other properties of the input box:
i didn't see anything that resembles the actual input.
Nor could i find a way to tell if the box "is empty", or not. Maybe i could have inferred:
value isEmpty Conclusion
============= ============= ================
"4" false valid number
"" true empty box; not a problem
"" false invalid text; color it red
Note: You can ignore everything after the horizontal rule; it's just filler to justify the question. Also: don't confuse the example with the question. People might want the answer to this question for reasons other than coloring the box red (One example: converting the text "four"
into the latin "4"
symbol during the onBlur event)
How can i get the "raw" value of an <input type="number">
control?