[jQuery] How to clear setTimeout?

[jQuery] How to clear setTimeout?


Hi,
I'm trying to implement an autoSave function on my web application.
Something that automatically saves the contents of the current field 6
seconds after the last keyUp. It works, but I can't clear the multiple
setTimeouts triggered on each keyUp event.
Example:
    $("input").keyup(function(){
        var self = this;
        var upd = setTimeout( function() {
            updateField( $(self) ); // function outside $ scope to update field
contents in dB
        },6000);
    });
I must've tried about 27 permutations of clearTimeout, setting flag
variables, nullifying variables, etc. Nothing has worked.
To be clear, I need to "restart the countdown" to update the field if a user
presses another key within 6 seconds of the previous letter. I'd rather not
be shooting off POSTs on every keystroke ;)
(BTW, I've used the onChange event before, but for text inputs, the user has
to manually tab/click out of the field to trigger that event)
Thanks,
_________
SEAN O
http://www.sean-o.com
--
View this message in context: http://www.nabble.com/How-to-clear-setTimeout--tf4601640s27240.html#a13138432
Sent from the jQuery General Discussion mailing list archive at Nabble.com.