Event on a timer which resets after each keystroke? Javascript.

152 views Asked by At

Trying to trigger a beep after 10 seconds of not-typing occurs in a chatbox.

Thinking about building in beeping event linked t with a 10 second timer which resets with each keystroke. any ideas?

1

There are 1 answers

0
VSri58 On

I guess the solution you expect will be similar to this

Code:

var timer; 

$('#tArea').keyup(function(){
    clearTimeout(timer);
    timer = setTimeout(yourAction, 10000); // interval is set to 10s
});

$('#tArea').keydown(function(){
    clearTimeout(timer);
});

function yourAction () {
    // Your code goes here
    alert("You have not typed anything for the past 10 seconds!!");
}

Check the Demo