Action after user stops typing

hey I am trying to write this code where it watches a user typing in a text box and then once the user has finished typing it does a certain action. I was thinking maybe run a timer after every keypress and if the user does not press a key within 2 seconds of the last one it exicutes the action. If any of you have a more efficient way of doing this please post it. Anyways what I have so far is

[AS]this.onKeyDown = function() {
function doneDelay(){
loadVariablesNum(“write.php”, 0, “POST”);
clearInterval(delay);
}
delay = setInterval(doneDelay, 2000);
}
Key.addListener(this);
[/AS]

this works somewhat but it exciutes continuouly after the user stops typing :frowning: