Trigger JavaScript Function After User Finishes Typing



To fire a JavaScript function when the user finishes typing, try to run the following code −

Example

<html>
   <body>
      <script>
         var timer = null;
         $("#myText").keydown(function(){
            clearTimeout(timer);
            timer = setTimeout(doStuff, 1000)
         });
         function doStuff() {
            alert("Write more!");
         }
      </script>
      <input type = "text" id = "myText" />
   </body>
</html>
Updated on: 2020-06-16T11:47:11+05:30

301 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements