Calling an AJAX function using the Enter Key - Javascript DOM

Javascript examples for DOM:Key Event

Description

Calling an AJAX function using the Enter Key

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 ww . ja v  a  2  s . c o m*/
});

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

Related Tutorials