javascript search after user stops typing

Solutions on MaxInterview for javascript search after user stops typing by the best coders in the world

showing results for - "javascript search after user stops typing"
Christopher
08 Nov 2018
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