function addInputCallback(theInput,callback,delay){ var timer=null; var theOldValue = ''; theInput.onkeyup=function(event){ if ( typeof event == "undefined" ) event = window.event; var key=event.keyCode; var keychar = String.fromCharCode(key); keychar = keychar.toLowerCase(); if (key == 13) { // if enter key, call callback() function immediately timer=null; callback(); theInput=null; } if (isAlphanumericInput(keychar) || key == 8 || key == 46) { // backspace and delete chars if(timer) { window.clearTimeout(timer); } timer=window.setTimeout(function(){ timer=null; callback(); } ,delay); theInput=null; } }; } function isAlphanumericInput(theInputChar) { if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(theInputChar) > -1)) { return true; } }