check key code from event keyCode and which property - Javascript DOM

Javascript examples for DOM:Key Event

Description

check key code from event keyCode and which property

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
var arrForbiddenCodes = [97, 98, 99];
function CheckKey(event) {/*from   w  w w .j  av a2s.c  om*/
    var keyCode = event.keyCode || event.which;
    for (var i = 0; i < arrForbiddenCodes.length; i++) {
        if (arrForbiddenCodes[i] === keyCode)
            return false;
    }
    return true;
}

      </script> 
   </head> 
   <body> 
      <textarea onkeypress="return CheckKey(event);"></textarea>  
   </body>
</html>

Related Tutorials