Spoonk Spoonk - 1 year ago 138
Javascript Question

OnKeyUp JavaScript Time Delay?

Hi Again Masters Of The Web :)
Now, I have got a new stupid question, and I am asking to forgive me. I read everywhere about this solution, but didn't find the one that works for me.

I have got:

<input name="domain" type="text" id="domain" onKeyUp="javascript:chk_me();">

All I am asking is how to make this not to check after a button is pressed, but after to say 1000 miliseconds of keyboard inactivity?

Answer Source

Try this:

var timer;
function chk_me(){
   timer=setTimeout(function validate(){...},1000);

In this way every time a key is pressed, the timeout will be deleted and the set again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download