manish250 0 Junior Poster in Training

hello all

i have a jsp page in which i am using a function for detecting the ascii value of key pressed.it has to give alert if other than any alphabet key is pressed.Below giving the explaining code

function checkname(e)
   {
             var cc=e.keyCode;

             if(cc >=65 && cc <=90 || cc >=97 && cc<=122)
             {
                         return true;
              }
           else
            {                   alert (""+cc+"");
                           alert("Enter only alphabets");
                            return false;
            }
 }

 <td><input type="text" name="name" maxlength="20" onkeypress="return checkname(event);" /></td>
                                
                                <td width="57%"><input type="text" name="user_id" maxlength="20" onkeypress="return checkname(event);"/></td>

but when i go to write any alphabet in textbox it gives alert "Enter only alphabets".i have printed the value of key pressed it is showing every time zero.


Please note that this problem is occuring in Mozilla browser.In Internet explorer it is working fine as it should be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.