showing results for - "javascript wait for user to stop typing"
Ida
20 Nov 2016
1/*this will delay the doneTyping function
2until 1 second after the user stops typing*/
3var isUserTypingTimer;
4var doneTypingInterval = 1000;// wait for 1 second b4 sending requests
5
6function doneTyping () {
7    //make request here
8}
9
10document.getElementById("myInput").addEventListener('keyup', function(event){
11     clearTimeout(isUserTypingTimer);
12     isUserTypingTimer = setTimeout(doneTyping, doneTypingInterval);
13});
14document.getElementById("myInput").addEventListener('keydown', function(event){
15    clearTimeout(isUserTypingTimer);
16});