Issue
I have validation to accept the min and max value for an input type="number" field. Once I entered some input it is working according to the max and min value. What is my problem is I could not able to clear/delete an entered value in the number field. In textbox field, it is allowing to clear the value by using backspace and selecting the number and type new number. why number field is not working in that scenario. how to make it clear/delete the number in the number field.
<input type="number" name="WorkingDaysPA" id="WorkingDaysPA"
min="1" max="366" style="text-align: right"
onkeypress="if(this.value.length==3) return false;return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57"
/>
<input type="text" maxlength="3" min="1" max="366">
Here My fiddle: https://jsfiddle.net/MariNithya/fpd2y4f4/
Solution
On focus out event, I am assiging null as value;
Hope this helps
document.getElementById("validateNums").addEventListener("focusout", inputOutOfFocus);
function inputOutOfFocus() {
document.getElementById("validateNums").value = null;
}
<input type="number" maxlength="3" min="1" max="366" id="validateNums">
Answered By - Rajkumar Somasundaram
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.