Handle OnKeyDown event and use String.FromCharCode to get key code - Javascript DOM Event

Javascript examples for DOM Event:onkeydown

Description

Handle OnKeyDown event and use String.FromCharCode to get key code

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function PreventDigits(evt) {// w  w w  .j  a v  a 2  s . c o m
    evt = evt || window.event;
    var keyCode = evt.keyCode || evt.which;7
    var num = parseInt(String.fromCharCode(keyCode), 10);
    return isNaN(num);
}

      </script> 
   </head> 
   <body> 
      <input type="text" onkeypress="return PreventDigits(event);">  
   </body>
</html>

Related Tutorials