Tuesday, May 07, 2013

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>

jQuery(window).load(function() {

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

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

//user is "finished typing," do something
function doneTyping () {

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

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