I have an input on an HTML page where a person will type something and what I’m wanting is for a function to be called every time they stop typing. I know about the onkeypress event, but that is called every time a character is typed. Here’s an example of what I would like:
- Person types “this is a test” into the input
- After the person stops typing, function foo() should be called
- Person types something else into the input
- After the person stops typing, function foo() should be called
- Repeat….
Is this possible?
Thanks a lot!
Listen to onkeyupevent. There start a timeout (you have to define “stop” as some time amount, otherwise it will be called at every keyup), and in the timeout execute your function.
If onkeydown is called while your timer is running, stop it.
Something like…
How this code exactly looks depends where and how you are using it… just to show the way to do it.