I'm a little weak (or maybe a lot weak) with client side scripting. I am trying to implement a delayed call to do an ajax save based on waiting 500ms after the user stops typing.
I found this great solution here. But my resulting function needs the original element that triggered the save. How can I pass this value through?
Here is my calling code:
$('#OrderDetailsTabs').on('keyup', 'form[id^="frmWorkOrderHdr"] textarea', function (event) {
var thisElement = this;
delay(function (thisElement) {
alert('Time elapsed!');
saveWOHdr(thisElement);
},
1000);
})
Here is the delay variable definition:
var delay = (function () {
var timer = 0;
return function (callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
saveWOHdr needs the originating element to be passed to it.