I want the number type html input element to take the input through keyboard, and if the last number pressed makes it exceed the max value, that last key press should be discarded.
I tried using javascript to accomplish that.
Here's the code
<input type="number" id = 'customer-age-input' max="120" min="0" onkeypress="javascript: if (int(this.value) > int(this.max)) this.value = 0;">
What is actually happening is different from expected. It takes whatever inout I type-'123', '1234' etc. but when I press the arrow up key it doesn't increase the value as it does by default when the value is less than max. Also, when I press arrow-down key, it reduces it to the max value.
Aucun commentaire:
Enregistrer un commentaire