HTML event attribute oninput

The oninput attribute event is triggered when the value of an <input> or <textarea> element is changed.

The oninput attribute event is similar to the onchange event.

The oninput event occurs immediately after the value of an element has changed. The onchange event occurs when the element loses focus.

The onchange event also works on <select> elements.

What's new in HTML5

The oninput attribute is new in HTML5.


<element oninput="script or Javascript function name">

Supported Tags

<input type="password">, 
<input type="search">, 
<input type="text"> 

Browser compatibility

oninput Yes Yes Yes Yes Yes


<!DOCTYPE html>
<!--from  ww  w .  j a va2s .  co  m-->
<input type="text" id="myInput" oninput="myFunction()">

function myFunction() {
    var x = document.getElementById("myInput").value;


Click to view the demo