So referencing this:
How to delay the .keyup() handler until the user stops typing?
I came up with the following code. But it does nothing… Any suggestions?
I am trying to get the setTimeout to cancel if the user types something further, so that multiple alerts don’t happen, only one when the user finally ‘stops’ (hopefully).
Thanks!!
var t = 0;
$('input').keyup(function(){
clearTimeout(t);
t = setTimeout(alert($('input').val()),1000);
}
Replace
with
You were passing the value of the input to setTimeout, while setTimeout needs a function (or a string it can evaluate as code) as first argument.
And replace the last line with
});so that the code compiles.Demonstration