I have a input number which should always a default value as zero
Incase the user has done a backspace or delete button and removed the value how can i put default value zero as back
This is my code
$(document).ready(function () {
$(".numbersonly").keypress(function (e) {
if(this.value.length=='0')
{
$(this).val('0');
return false;
}
if(this.value.length==2) return false;
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Digits Only").show().fadeOut("slow");
$(this).val('0')
return false;
}
});
});
This is my fiddle