oninput Event
Example
Call a function when a user writes something in an <input> field:
<input type="text" oninput="myFunction()">
Try it Yourself »
More examples below.
Description
The oninput
event occurs when an element gets input.
The oninput
event occurs when the value of an <input> or
<textarea> element is changed.
The oninput
event does NOT occur when a <select>
element changes.
Note
The oninput
event is similar to the
onchange
event.
The difference is
that the oninput
event occurs immediately after the content
has been changed, while onchange
occurs when the element loses focus.
Syntax
In JavaScript, using the addEventListener() method:
object.addEventListener("input", myScript);
Try it Yourself »
Technical Details
Bubbles: | Yes |
---|---|
Cancelable: | No |
Event type: | Event, InputEvent |
HTML tags: | <input> and <textarea> |
DOM Version: | Level 3 Input Events |
More Examples
Example
Range slider - how to dynamically update slider value:
<input type="range" oninput="myFunction(this.value)">
Try it Yourself »
Browser Support
oninput
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.