Run javascript/jQuery function when user finishes typing instead of on key up.


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script>!window.jQuery && document.write(unescape('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script>

             <script>
jQuery(window).load(function() {

//setup before functions
var typingTimer;                //timer identifier
var doneTypingInterval = 500;  //time in ms

//on keyup, start the countdown
jQuery('.UI-SEARCH').keyup(function(){
   clearTimeout(typingTimer);
   if (jQuery('.UI-SEARCH').val) {
  typingTimer = setTimeout(doneTyping, doneTypingInterval);
   }
});

//user is "finished typing," do something
function doneTyping () {
   alert('hi');
}
});
</script>


<body>
<input type="text" maxlength="128" value="" name="q" autocomplete="off" class="input-text UI-SEARCH">
</body>


Delay keystroke/keyup/keydown action until user complete the type in text box.

Comments

Popular posts from this blog

AIOMgr: Preparing flush failed with VERR_NOT_SUPPORTED, disabling async flushes

Create Virtual Host in IIS Server

The model type is invalid. please select an item from the list ( ASP.Net MVC)