admin管理员组文章数量:1287579
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: /
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/MariNithya/fpd2y4f4/
Share Improve this question edited Jan 8, 2019 at 13:11 Cœur 38.7k26 gold badges203 silver badges277 bronze badges asked Nov 17, 2017 at 6:09 N15N15 3052 gold badges4 silver badges17 bronze badges 2- fiddle link broken. – Rajkumar Somasundaram Commented Nov 17, 2017 at 6:12
- now, fiddle is working. – N15 Commented Nov 17, 2017 at 6:14
2 Answers
Reset to default 8On 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">
to clear the text field we use document.getElementById("exampleId").textContent = ""; whereas to clear number field use document.getElementById("exampleId").value =null ;
hope this solves your problem.
本文标签:
版权声明:本文标题:javascript - input type="number" is not able to deleteclear on selecting the number in Firefox and IE - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741287173a2370339.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论