How can I call a function after a person stops typing?

I have an input on an HTML page where a person will enter something, and what I want is a function that needs to be called every time they stop typing. I know about the onkeypress event, but this is called every time a character is typed. Here is an example of what I would like:

  • Character type "this is a test" in the input
  • After the user stops typing, the function foo () should be called
  • Person enters something else into the entrance
  • After the user stops typing, the function foo () should be called
  • Repeat ....

Is it possible?

Thank you so much!

+5
source share
4 answers

onkeyupevent. - ( "" , ), - .

onkeydown, .

- ...

var timer;

function onKeyUpHandler(e){
    timer = setTimeout("foo()", 500)    
}

function onKeyDownHandler(e) {
    clearTimeout(timer);
}

, , ... .

+10

javascript / onKeyPress. , " " script.

0

"key up" "stopTyping" true. ( , " " ).

, , "", "stopTyping = false"

, "stopTyping". , (, ). , - , , char .

0

If I understand well, "stop typing" means "no keystrokes for a certain amount of time." In this case you need to use timers: http://jsfiddle.net/xnghR/1/

0
source

All Articles