Get key code from key event - Javascript DOM

Javascript examples for DOM:Key Event

Description

Get key code from key event

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script language="Javascript">
   function isNumberKey(evt)/*ww w.  ja  v a 2  s. com*/
   {
      var charCode = (evt.which) ? evt.which : event.keyCode;
      if (charCode != 46 && charCode > 31
        && (charCode < 48 || charCode > 57))
         return false;
      return true;
   }

      </script> 
   </head> 
   <body> 
      <input name="x" style="width:100%;height:40px;font-size:15px;" id="txtChar" onkeypress="return isNumberKey(event)" type="text">  
   </body>
</html>

Related Tutorials