You forgot to call e.preventDefault() .
function checkerFunction1(e) { e = e || window.event; var charCode1=e.which || e.keyCode; if( (charCode1 >= 65 && charCode1 <= 90) || (charCode1 >= 97 && charCode1 <= 122) || (charCode1==32 || charCode1==8 || charCode1==46) ) return true; return e.preventDefault(), false; }
see this script .
It is best to attach event listeners to the DOM elements when the window loads, and not through the html attributes, as it separates your HTML from your JavaScript. It also has the added advantage of choosing when you want to capture the event itself.
You can still capture window.event inside the function, if absolutely necessary for compatibility.
The " undefined " problem in Firefox comes from event , which is considered more as a keyword than a variable, so window.event === undefined , but event !== undefined , so if you want to save a thing as an attribute, you can do it like this
onkeypress="return checkerFunction1(window.event||event)"
source share