Skip to content

Instantly share code, notes, and snippets.

@faridfr
Last active May 11, 2019 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faridfr/7325e6a980e8e20baa0afa164fbceea7 to your computer and use it in GitHub Desktop.
Save faridfr/7325e6a980e8e20baa0afa164fbceea7 to your computer and use it in GitHub Desktop.
afterTextChanged in html and javascript
// Use ( onkeyup="afterTextChanged(this);" ) in your input element
// This function works after user typing . You can change sensivity in line 17
oldKey = 0,differenceInKeyTime = 0,newKey = 0,interval = 0;
function afterTextChanged (element){
if(element.value.length == 0)
return 0;
oldKey = new Date();
clearInterval(interval);
startTiming();
}
function startTiming(){
interval = setInterval(function() {
newKey = new Date();
differenceInKeyTime = (newKey.getTime() - oldKey.getTime()) / 1000;
if(differenceInKeyTime>0.9)
{
clearInterval(interval);
// Do your action here . For example send ajax request .
}
},10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment