I have not used this before just now and noticed it does not update its value in html?
Basically i have a Html Table with this in it , and user will update it to a quantity needed and Submit and i will take the Html parse it to get the things.
But in the html i see the value of input box is always 1, i it never updates itself
<input type="number" id="testNumber" value="1" min="1" max="100" />
By default, HTML 5 input field has attribute type=”number” that is used to get input in numeric format. Now forcing input field type=”text” to accept numeric values only by using Javascript or jQuery. You can also set type=”tel” attribute in the input field that will popup numeric keyboard on mobile devices.
The <input type="number"> defines a field for entering a number. Use the following attributes to specify restrictions: max - specifies the maximum value allowed. min - specifies the minimum value allowed.
HTML Input element is documented to return the value in String type representing number.
While yes, the markup indicates that the value is still 1, if this form were to be submitted, the displayed value of the number input would still get returned.
You can verify this by running the following in your browser's console:
var input = document.getElementById('testNumber');
input.value;
EDIT 1:
If you want the value of the html to match the value of the dom element, assign it yourself, like so:
input.setAttribute('value', input.value);
This is just a sample. But it handles the INCREASE(+)/DECREASE(-) buttons clicked and updates the input value.
$("input[type=number]").click(function(e) {
$(this).attr( 'value', $(this).val() );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With