I have the following code:
function noNumbers(e)
{
var charCode = (e.which) ? e.which :
((e.charCode) ? e.charCode :
((
You can simply add console.log(e);
in your function and debug what's going on:
Chrome/IE doesn't call this function on Backspace
and Delete
key press. Firefox logs keypress { target: , key: "Backspace", charCode: 0, keyCode: 8 }
and keypress { target: , key: "Delete", charCode: 0, keyCode: 46 }
respectively. So there is two solutions:
1) Add if
for these keyCode
s (8 and 46)
2) Do not use keypress
event and use keydown
instead (as @Teemu wrote).