Trigger a function if TYPING STOPPED

HTML


<input type="text" id="username" />

JS

var timeoutReference;
$(document).ready(function() {
$('input#username').keypress(function() {
var _this = $(this); // copy of this object for further usage
if (timeoutReference) clearTimeout(timeoutReference);
timeoutReference = setTimeout(function() {
alert(_this.val());
}, 3000);
});
});

JS FIDDLE

Advertisements