Trigger a function after user stopped typing for 3 seconds
http://stackoverflow.com/questions/14042193/how-to-trigger-an-event-in-input-text-after-i-stop-typing-writing
<input type="text" id="shipfrom_zip" required="true">
<input type="text" id="shipto_zip" required="true">
<input type="text" id="pallets" required="true">
<input type="text" id="shipdate" required="true">
<script>
$( document ).ready(function() {
// set time in seconds
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
/*
- run initialize if all 3 input fields are not empty
- delay this for 3 seconds
*/
$("#shipfrom_zip, #shipto_zip, #pallets").keyup(function () {
if ($('#shipfrom_zip').val() != 0 && $('#shipto_zip').val() != 0 && $('#pallets').val() != 0 ) {
// Delay keyup for 3 seconds
delay(function(){
initialize() ;
}, 3000 );
console.log("initialize() ") ;
}
});
});
</script>