oninput Event
Definition and Usage
The oninput event occurs when the element receives user input.
This event occurs when the value of an <input> or <textarea> element changes.
Tip:This event is similar to onchange Event. The difference is that the oninput event occurs immediately after the element value changes, while onchange occurs when the element loses focus and the content changes. Another difference is that the onchange event also applies to <select> elements.
Instance
Example 1
Execute JavaScript When User Writes Content in <input> Field:
<input type="text" oninput="myFunction()">
Example 2
Range Slider - How to Dynamically Update Slider Value:
<input type="range" oninput="myFunction(this.value)">
Syntax
In HTML:
<element oninput="myScript">
In JavaScript:
object.oninput = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("input", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method.
Technical Details
Bubbling: | Support |
---|---|
Cancelable: | Not supported |
Event Type: | Event, InputEvent |
Supported HTML Tags: | <input type="color">, <input type="date">, <input type="datetime">, <input type="email">, <input type="month">, <input type="number">, <input type="password">, <input type="range">, <input type="search">, <input type="tel">, <input type="text">, <input type="time">, <input type="url">, <input type="week"> and <textarea> |
DOM Version: | Level 3 Events |
Browser Support
The numbers in the table indicate the first browser version that fully supports the event.
Events | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
oninput | Support | 9.0 | 4.0 | 5.0 | Support |