Keyup only after last key with jquery
jquery
Solution
var timer;
$("input").on('keyup', function() {
clearTimeout(timer); //clear any running timeout on key up
timer = setTimeout(function() { //then give it a second to see if the user is finished
//do .post ajax request //then do the ajax call
}, 1000);
});
Problem
I'm coding a simple script to extract database informations on input keyup event. The problem i have is that the keyup event is always repeated everytime the user press a key. How can i make it working only after the last key pressed? I think i should use a function like setTimeOut() after every keyup, But i don't know how... can you make me a simple example please? Sorry for my bad english :) Here is what i was trying to do: ``` $("input").keyup(function() { var timer=setTimeout(function() { }, 1000); if(!timer) { //do .post ajax request } }); ```