Created
July 20, 2016 13:17
-
-
Save kamichidu/150e11af71425ce38cbc5dd8110183b8 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Input box and delayed api calling example</title> | |
</head> | |
<body> | |
<input id="delay" type="text"> | |
<script> | |
(function(){ | |
var query= document.getElementById('delay'); | |
var toId= null; | |
var delay= 500; | |
var callApi= function(){ | |
console.log('callApi', query.value); | |
}; | |
var doDelayedQuery= function(evt){ | |
if(toId) | |
{ | |
clearTimeout(toId); | |
toId= null; | |
} | |
toId= setTimeout(callApi, delay); | |
}; | |
query.addEventListener('input', doDelayedQuery, false); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment