While using some javascript, I have noticed that if there is a "-" (or "+") in a number input field, if I call the .value
function on it, the value returned will be "" (undefined)!
I can understand where it came from: this way, the value returned will be a consistent number all the time, function like this that returns the string "-" (or "+") will cause troubles.
However, in my implementation, I want to detect this scenario. Is there any way that I can differentiate the inputs "" (undefined) and "-" (or "+") in an <input type="number"/>
field using JavaScript? maybe with something with jQuery instead?
Below you can see a small example of the scenario I'm talking about. Thanks in advance!
function updatevaluefield() {
value_span = document.getElementById("value_field");
input = document.getElementById("input");
value_span.innerHTML = input.value;
}
function updateinputvalue() {
input = document.getElementById("input");
input.value = "-";
updatevaluefield();
}
<input id="input" type="number" value="123"/>
<button onclick="updateinputvalue()">Set input field to "-"</button><br/>
<br/><br/>
The value of the input field is: <span id="value_field"></span> <br/>
<button onclick="updatevaluefield()">Show value (update)</button>