HTML onchange Attribute

❮ HTML Attributes

Example

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

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

<script>
function myFunction() {
  var x = document.getElementById("fname");
  document.getElementById("demo").innerHTML = x.value;
}
</script>

Meaning

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




Status




Applies to:

The onchange attribute can be used on the following element:

Element Attribute
All HTML elements onchange






Attribute Values

Value Description
script Specifies the script to be run on onchange
❮ HTML Attributes