I'm attempting to limit an input field to characters only as documented in this SO post. The javascript works great but as noted here and elsewhere it doesn't work when the shift key is pressed. so I can hold the shift key, type 5 and a '%' shows up. So I added this code to simply return on keydown events in which event.shiftKey = true
$(document).on("keydown", ".numbers-only", function (event) {
if(event.shiftKey){
return
}
numbersOnly(event);
});
This works when I set a breakpoint and step through with the debugger in chrome. However, it does not work in realtime and the numbersOnly(event) function is called even while holding the shift key down.
Why would the function return as it should while debugging, but not in real time?