HTML onchange Attribute

❮ HTML 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


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