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 begivenhed. 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.

Example

Example 1

Execute JavaScript when the user writes content in the <input> field:

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

Try it yourself

Example 2

Range slider - how to dynamically update the slider value:

<input type="range" oninput="myFunction(this.value)">

Try it yourself

Syntax

In HTML:

<element oninput="myScript">

Try it yourself

In JavaScript:

object.oninput = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("input", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.

Technical details

Bubble: 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"> samt <textarea>
DOM version: Level 3 Begivenheder

Browserunderstøttelse

Tallene i tabellen angiver den første browserversion, der fuldt ud understøtter begivenheden.

Begivenheder Chrome IE Firefox Safari Opera
oninput Support 9.0 4.0 5.0 Support