HTML oninput Attribute

HTML oninput Attribute: This attribute is defined as it fires when an element gets user input. And this attribute mainly fires when the user changes the value of <input> and <textarea> element. It is quite similar to onchange attribute but the basic difference is that the oninput event attribute occurs immediately when the value of element changes while the onchange attribute occurs when the element loses Focus. While the other difference is that onchange attribute also works with the <select> element.

HTML oninput Attribute

This attribute can be applied to all the HTML elements. This attribute contains value script and it works when oninput event triggered. This attribute is supported by many HTML tags: <input type=”password”>, <input type=”search”, <input type=”text”> and <textarea>.

Syntax: <element oninput = “script”>

Browser Support

This attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Internet Explorer
  • Safari
  • Opera

Example: for <input> element

<!DOCTYPE html>
<input type="text" id="myInput" oninput="myFunction()">
<p id="demo"></p>
function myFunction() {
  var x = document.getElementById("myInput").value;
  document.getElementById("demo").innerHTML = "You wrote: " + x;


HTML oninput attribute