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.

Syntax

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

Supported Tags

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




Browser compatibility

oninput Yes Yes Yes Yes Yes

Example

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

<script>
function myFunction() {
    var x = document.getElementById("myInput").value;
    console.log(x);
}
</script>

</body>
</html>

Click to view the demo