oninput
Event
Example
Execute JavaScript when a user attempts to input into an <input>
:
<input type="text" oninput="myFunction()">
Definition and Usage
The oninput event is triggered when the user inputs data.
This event is fired when the value of an <input>
or <textarea>
element changes.
Tip: This event is similar to the onchange event. The difference is that the oninput event occurs immediately after the value of an element has changed, while the onchange event occurs when the element loses focus. Another difference is that the onchange event also works on <keygen>
and <select>
elements.
Browser Support
The numbers in the table specify the first browser version that fully supports the event.
Event | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
oninput | Yes | 9.0 | 4.0 | 5.0 | Yes |
Syntax
In HTML:
In JavaScript:
In JavaScript, using the addEventListener() method:
Note: Internet Explorer 8 and earlier versions do not support the addEventListener() method.
Technical Details
Bubbles: | Yes |
---|---|
Cancelable: | No |
--- | --- |
Event Type: | Event |
--- | --- |
Supported HTML Tags: | <input type="password"> , <input type="search"> , <input type="text"> , and <textarea> |
--- | --- |