clearTimeout not working in javascript autocomplete script

Posted by Travis on Stack Overflow See other posts from Stack Overflow or by Travis
Published on 2010-04-11T22:00:30Z Indexed on 2010/04/11 22:03 UTC
Read the original article Hit count: 288

Filed under:
|
|

I am using the following code as part of an autocomplete script to avoid hammering the server with every keystroke:

var that = this;

textInput.bind("keyup", function() {

    clearTimeout(that.timer);

    that.timer = setTimeout (that.doStuff(), 2000);

});

Unfortunately, this does not clear the old timers. They still all execute.

Does anyone know what I'm missing?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery