let timer; // Timer identifier const waitTime = 500; // Wait time in milliseconds // Search function const search = (text) => { // TODO: Make HTTP Request HERE }; // Listen for `keyup` event const input = document.querySelector('#input-text'); input.addEventListener('keyup', (e) => { const text = e.currentTarget.value; // Clear timer clearTimeout(timer); // Wait for X ms and then process the request timer = setTimeout(() => { search(text); }, waitTime); });
let timer; // timer identifier const waitTime = 500; // Wait time in milliseconds
// search function const search = (text) => { // to do: make http request here }
// Listen for keyup
event
const input = document.querySelector('#input-text');
input.addEventListener('keyup', (e) => {
const text = e.currentTarget.value;
// clear timer
clearTimeout(timer);
// Wait for X ms and then process the request timer = setTimeout(() => { search(text); }, waitTime); });