Last active
May 11, 2019 14:37
-
-
Save faridfr/7325e6a980e8e20baa0afa164fbceea7 to your computer and use it in GitHub Desktop.
afterTextChanged in html and javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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