0

Run javascript function when user finishes typing instead of on key up?

var typingTimer;                //timer identifier
var doneTypingInterval = 300;  //time in ms, 300ms for example
var $input = $('#myInput');

//on keyup, start the countdown
$input.on('keyup', function () {
  clearTimeout(typingTimer);
  typingTimer = setTimeout(doneTyping, doneTypingInterval);
});

//on keydown, clear the countdown 
$input.on('keydown', function () {
  clearTimeout(typingTimer);
});

//user is "finished typing," do something
function doneTyping () {
  //do something
  console.log('finished typing', $input.val()); 
}
<input id="myInput" placeholder="type some text..."/>
input {
  padding: 20px;
  font-size: 20px;
}
RUN
add comment
Suggest a different solution or add another example