I am facing problem in validation. It is working in google chrome, but not in Mozilla.
Like: I have a form where Name: ____ .
I want to put a validation so that the user can’t write a numeric value.
Inside the javascript:
function checkerFunction1(e)
{
var charCode1=e.which || e.keyCode;
if((charCode1 >= 65 && charCode1 <= 90) ||(charCode1 >= 97 && charCode1 <= 122) ||(charCode1==32 || charCode1==8 || charCode1==46))
return true;
return false;
}
Inside the jsp page:
<input type="text" value="Name" onkeypress="return checkerFunction1(window.event)"/>
Why it is not working in Mozilla?
This should fix it:
The condition in the
if‘s brackets is a boolean already. The if is not needed when you want to return atrueorfalse, you were basically saying:Firefox was telling me “e is undefined”
You’ll need to use the
eventobject for that browser (as seen above)preventDefault()is not needed. Returningfalsewill prevent Firefox from entering a false key into the field.