Fire Event After Pressing ENTER in HTML Text Input



Use HTML with jQuery to achieve this and fire after pressing ENTER −

Example

<!DOCTYPE html>
<html>
   <head>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
         $(document).ready(function(){
            $('input').bind("enterKey",function(e){
               alert("Enter key pressed");
            });
            $('input').keyup(function(e){
               if(e.keyCode == 13)
               {
                  $(this).trigger("enterKey");
               }
            });
         });
      </script>
   </head>
 
   <body>
      <input type = "text">
      <p>Press Enter key in the above input text.</p>
   </body>
</html>
Updated on: 2020-06-25T07:28:39+05:30

408 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements