The oninput event is not supported in IE6, IE7, and IE8.
Even oninput event is supported in IE9, it is still buggy.
Although we can use onpropertychange event in IE browser, it is still very
difficult to maintain a consistent behavior. So here comes the question:
How do we detect the content change of HTML input elements in a cross-browser and consistent way?
The solution is inspired by the library in reference [3]. It is simple, use
JavaScript built-in setTimeout or setInterval function to periodically check
the content of input elements, and if the content changes, then an event
handler function is fired to handle this event. I wrote the following example to
demonstrate the solution:
<!doctype html><html><head><metacharset="utf-8"><title>JavaScript oninput and onpropertychangte Event Alternative</title></head><body><inputid="input"type="text"><divid="info">Type something in above input.</div><scriptsrc="polling.js"></script><scripttype="text/javascript">// focus to input element.document.getElementById('input').focus();// start to polling input elementpolling();</script></body></html>
/** * event handler to be fired if the content of input element have changed. */functioneventHandler(){// write your own event handler here.document.getElementById('info').innerHTML='input content changed to '+document.getElementById('input').value;}/** * Variable which keeps track of the content of input element * @type {string} */INPUT_CONTENT='';/** * Check input element periodically. */polling=function(){if(INPUT_CONTENT!=document.getElementById('input').value)eventHandler();// update INPUT_CONTENTINPUT_CONTENT=document.getElementById('input').value;// polling interval: 500ms.// you can change the polling interval to fit your need.setTimeout(polling,500);};