HTML onchange event Attribute

❮ HTML Event Attributes


<input type="text" name="fname" id="fname" onchange="myFunction()">

<p id="demo"></p>

function myFunction() {
  var x = document.getElementById("fname");
  document.getElementById("demo").innerHTML = x.value;


The onchange attribute fires when the form control has lost user focus and its value has been modified during its last access.

Standard Syntax

<element onchange="script">

Browser Support


Attribute Values

Value Description
script Specifies the script to be run on onchange

Technical Details

Supported HTML elements:

<input type="checkbox">, <input type="file">, <input type="password">, <input type="radio">, <input type="range">, <input type="search">, <input type="text">, <select> and <textarea>
❮ HTML Event Attributes