1//setup before functions
2var typingTimer; //timer identifier
3var doneTypingInterval = 5000; //time in ms, 5 second for example
4var $input = $('#myInput');
5
6//on keyup, start the countdown
7$input.on('keyup', function () {
8 clearTimeout(typingTimer);
9 typingTimer = setTimeout(doneTyping, doneTypingInterval);
10});
11
12//on keydown, clear the countdown
13$input.on('keydown', function () {
14 clearTimeout(typingTimer);
15});
16
17//user is "finished typing," do something
18function doneTyping () {
19 //do something
20}
21