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;

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

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

input.addEventListener('input', restartTimer);
<input type="text" id="input">

<p>Sent:</p>
<p id="output"></p>

Post a Comment for "JavaScript JQuery Delay Oninput"