In a recent project I worked on I needed to add the functionality to make an AJAX call when the user has stopped typing in a textbox. A solution that I came up with is to keep a counter and have it increment on every key press and decrement after a specified time. When the counter = 0 then I know that the user is done typing.


// Create a global variable
var keyCount = 0;

// On keyup event for textbox
function onKeyUpOfMyTextBox(){
// a key was pressed, user is typing, update count
keyCount++;

// fire this event after a second
setTimeout( function(){
// reduce number of key count
keyCount--;

// key count is 0, user, is done typing
if( keyCount === 0 ){
// Do your stuff
}), 1000 );
}