Since you're setting the value of upd to a function containing the
setTimeout, you should be able to just
delete upd;
-Original Message-
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Sean O
Sent: Wednesday, October 10, 2007 10:39 AM
To:
Thanks for the suggestion, but I tried delete upd; before, after, even inside
my upd = setTimeout... function, and nothing happened -- the behavior is
still the same.
SEAN
Andy Matthews-4 wrote:
Since you're setting the value of upd to a function containing the
setTimeout, you should
The delete wouldn't work, Andy - Sean's upd variable goes out of scope
immediately, and you need to use clearTimeout, not just delete the variable.
Sean, you can change your code to:
var upd;
$(input).keyup(function(){
var self = this;
How about something like (not tested):
myNamespace = {
timer:null,
keyup:function(jqObj){
clearTimeout( myNamespace.timer );
myNamespace.timer = setTimeout(function(){
myNamespace.updateField(jqObj);
}, 6000);
},
updateField:function(jqObj){
// save using jqObj.val();
Aha! placing var upd; outside of the keyup function did the trick! I always
get tripped up on scope issues like this...
I'll look to your expire plugin for future use... for now, this gets me over
the hump. Thanks, Michael!
SEAN O
Michael Geary wrote:
The delete wouldn't
Of course, this code doesn't have any reason to be a jQuery plugin at all.
It could just be:
function expire( callback, interval ) {
var timer;
return function() {
clearTimeout( timer );
timer = setTimeout( callback, interval );
};
}
with
Sean O wrote:
$(input).keyup(function(){
var self = this;
var upd = setTimeout( function() {
updateField( $(self) ); // function outside $ scope to
update field
contents in dB
},6000);
});
The upd var will
7 matches
Mail list logo