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
Post a Comment