Skip to content Skip to sidebar Skip to footer

Javascript Jquery Delay Oninput

I have a html table which gets its values from a database through jQuery Ajax. Something like this
Than the java script: function showUser(row

Solution 1:

I actually just implemented something really similar. Basically, you want to set a timer via setTimeout that starts and resets when you receive an input.

const input = document.getElementById('input');
const output = document.getElementById('output');
let timer = null;

functionupdateDatabase() {
  // your code here, but for this example, I'll just change some text.
  output.textContent = input.value;
}

functionrestartTimer() {
  clearTimeout(timer);
  timer = setTimeout(updateDatabase, 300);
}

input.addEventListener('input', restartTimer);
<inputtype="text"id="input"><p>Sent:</p><pid="output"></p>

Post a Comment for "Javascript Jquery Delay Oninput"