Skip to content

Instantly share code, notes, and snippets.

@kamichidu
Created July 20, 2016 13:17
Show Gist options
  • Save kamichidu/150e11af71425ce38cbc5dd8110183b8 to your computer and use it in GitHub Desktop.
Save kamichidu/150e11af71425ce38cbc5dd8110183b8 to your computer and use it in GitHub Desktop.
<!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