jQuery 'input' event
oninput
event is very useful to track input fields changes.
However it is not supported in IE version < 9. But older IE versions has its own proprietary event onpropertychange
that does the same as oninput
.
So you can use it this way:
$(':input').on('input propertychange');
To have a full crossbrowser support.
Since the propertychange can be triggered for ANY property change, for example, the disabled property is changed, then you want to do include this:
$(':input').on('propertychange input', function (e) {
var valueChanged = false;
if (e.type=='propertychange') {
valueChanged = e.originalEvent.propertyName=='value';
} else {
valueChanged = true;
}
if (valueChanged) {
/* Code goes here */
}
});
Occurs when the text content of an element is changed through the user interface.
It's not quite an alias for keyup
because keyup
will fire even if the key does nothing (for example: pressing and then releasing the Control key will trigger a keyup
event).
A good way to think about it is like this: it's an event that triggers whenever the input changes. This includes -- but is not limited to -- pressing keys which modify the input (so, for example, Ctrl
by itself will not trigger the event, but Ctrl-V
to paste some text will), selecting an auto-completion option, Linux-style middle-click paste, drag-and-drop, and lots of other things.
See this page and the comments on this answer for more details.