Handle textarea key pressed event - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Textarea

Description

Handle textarea key pressed event

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 a  v a2 s  .  c o  m
    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