If I want to write in the input 149, the run method 3 times and the variable hour is 1, then 14 and then 149, what I'm looking for is that the changeHour method starts after 3000 ms since I stopped typing
function delay() {
var timer = 0;
return function(callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
}
function changeHour(elem) {
var id = $(elem).data("Id");
var hour = $(elem).val();
API_Loading.show();
var url = BASE_PATH + "Stage/UpdateHourOfStage";
API_ajaxWrapper_Library.ajax(url, {
method: "POST",
data: {
id: id,
hour: hour || 0
},
onDone: function(data) {
API_Loading.hide();
$("#saveIcon_" + id).show();
$("#saveIcon_" + id).fadeOut(3000);
},
onFail: function(result) {
API_Loading.hide();
alert("Error");
}
});
}
<div>
<div class="hour-num" style="background-color:#c4bed0;">Hours to go</div>
<input class="hour-num decimal" type="text" value="Hour" data-id="Id" onkeyup="delay(changeHour($(this)), 3000)">
</div>