oninputEvent

事件对象参考手册Event Object

Examples

Execute JavaScript when the user tries to enter input into <input>:

<input type="text" oninput="myFunction()">

Try it Yourself »


Definition and Usage

The oninput event triggers when the user inputs.

This event is triggered when the value of an <input> or <textarea> element changes.

Tip:This event is similar toonchangeevent. The difference is that the oninput event is triggered immediately when the element's value changes, while onchange is triggered when the element loses focus. Another difference is that the onchange event can also apply to <keygen> and <select> elements.


Browser Support

The numbers in the table indicate the first browser version that supports this event.

Event
oninput Yes 9.0 4.0 5.0 Yes


Syntax

In HTML:

<element oninput="myScript">Try it Yourself

In JavaScript:

object.oninput=function(){myScript};Try it Yourself

In JavaScript, using the addEventListener() method:

object.addEventListener("input", myScript);Try it Yourself

Note:Internet Explorer 8 and earlier IE versions do not supportaddEventListener()method.


Technical Details

Bubbles: Yes
Cancelable: No
Event type: Event
Supported HTML tags: <input type="password">, <input type="search">, <input type="text"> and <textarea>


事件对象参考手册Event Object

Other extensions