It might be better if you didn't use an anonymous function so you could
reference it multiple times. (I'm going to use a plugin I wrote that
jQuerizizes timer events cause it really simplifies the syntax of the
solution but something equivalent could be done without it.)
Example:
var fn = function(e) {
if (e.type == 'blur') $(this).stop();
// Do stuff
}
$(whatever).blur(fn).keyup(function() {
$(this).once(2000,fn);
}).keydown(function() {
$(this).stop();
});
Hope that helps.
-blair
Daemach wrote:
> I have a form with which I want to do ajax updates as they type. If they
> stop typing for more than 2 seconds it should update the field. If the
> field blurs before the 2 seconds are up it should update the field.
>
> I have the ajax side of it worked out, and currently the updates work
> properly when the field blurs. I just need some ideas on how to write the
> timer function for the keypresses and how it integrates with the blur
> function so the function doesn't get called twice and so there are no memory
> leaks from timers set then abandoned because the blur event got to it first.
>
> I'm going for elegance here :) I could write an outside function that gets
> called from both event handlers but that seems cheezy. There must be a way
> to do this with an anonymous function...
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/