Handler input box key event and check key code and key char - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Handler input box key event and check key code and key char

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>  Luke Boyle</title> 
   </head> 
   <body translate="no"> 
      <input id="myInfo"> 
      <script>
      document.getElementById('myInfo').addEventListener('keypress', function(event) {
  // you could also do keyCode === 13
  if (event.key === 'Enter') {
    console.log('do ajax request here');
  }/*from  w  w  w . jav  a 2 s.  co  m*/
});

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

Related Tutorials