Skip to content

Instantly share code, notes, and snippets.

@codeodor
Created January 14, 2010 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeodor/277293 to your computer and use it in GitHub Desktop.
Save codeodor/277293 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
timeOfLastKeyPress = new Date().getTime() * 2; // make it in the future
maxMillisecondsBetweenKeystrokes = 1000;
millisecondsBetweenCheckingForStoppage = 250;
function logKeyPress(){
timeOfLastKeyPress = new Date().getTime();
}
function userStoppedTyping(){
if(new Date().getTime() - timeOfLastKeyPress > maxMillisecondsBetweenKeystrokes){
alert("You stopped typing!");
clearInterval(intervalId);
}
}
intervalId = setInterval("userStoppedTyping()", millisecondsBetweenCheckingForStoppage);
</script>
<input type="text" id="field" onkeypress="logKeyPress();">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment