javascript - Number field that deletes non-numbers without clearing previous numbers? -
i using:
<input type="text" onkeyup="this.value = this.value.replace(/\d/g, '')">
i use prevent user entering except number field on page. however, noticed if user types number first accidentally hits non-number key, field cleared , have start over. may cause frustration wondering if there way tweak code not this, or if there similar method use. limited javascript, jquery, , html. appreciated! :)
i found solution issue. got rid of code above , ended using js function. put in within $(document).ready(function() hope helps same problem!
$("#mediansalary").keydown( function(event) { if (event.shiftkey || (event.keycode < 48 || event.keycode > 57) && (event.keycode < 96 || event.keycode > 105)) { event.preventdefault();} }); });
Comments
Post a Comment