Skip to content

Instantly share code, notes, and snippets.

@happymishra
Last active July 2, 2019 14:57
Show Gist options
  • Save happymishra/ed47cfa8f8c6705ea5eb454b32b66a1a to your computer and use it in GitHub Desktop.
Save happymishra/ed47cfa8f8c6705ea5eb454b32b66a1a to your computer and use it in GitHub Desktop.
<html>
<body>
<label>Search</label>
<!-- Renders an HTML input box -->
<input type="text" id="search-box">
<p>No of times user actually clicked</p>
<p id='show-api-call-count'></p>
</body>
<script>
var searchBoxDom = document.getElementById('search-box');
function makeAPICall() {
// This represents a very heavy method. Which takes a lot of time to
// execute
}
// Event listener on the input box
searchBoxDom.addEventListener('input', function () {
var apiCallCountDom = document.getElementById('show-api-call-count');
var apiCallCount = apiCallCountDom.innerHTML || 0;
apiCallCount = parseInt(apiCallCount) + 1;
// Updates the number of times makeAPICall method is called
apiCallCountDom.innerHTML = apiCallCount;
// A very heavy method which takes a lot of time to execute
makeAPICall()
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment