capture enter key press - Javascript DOM

Javascript examples for DOM:Key Event

Description

capture enter key press

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <input type="text" name="box22" value="please" onkeypress="handle(event)"> 
      <div id="msg1"></div> 
      <script type="text/javascript">
document.getElementById("msg1").innerHTML = "Default";
function handle(e){/*from   w ww  .j a v  a2s  .  c o  m*/
  document.getElementById("msg1").innerHTML = "Trigger";
  var key=e.keyCode || e.which;
  if (key==13){
     document.getElementById("msg1").innerHTML = "HELLO!";
  }
}

      </script>  
   </body>
</html>

Related Tutorials