HTML onchange Event Attribute


The event attribute onchange allows you to specify whether the script fires when the element values ​​change.

This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, and the onchange event occurs when the element loses focus. Another difference is that the onchange event has broader browser support and works with elements such as <keygen>, <select> and more extended with the <input> element.


<element onchange="script">


  • scriptThe name of the script to use when the event has been triggered.


<!DOCTYPE html> 
      <title>onchange event</title> 
    <p>Type any text and remove focus from the element:</p> 
    <input type="text" name="testInput" id="testInput" onchange="testFunction()"> 
    <p id="info2"> </p> 
function testFunction() { 
  var x = document.getElementById("testInput").value; 
  document.getElementById("info2").innerHTML="You typed the following text: " + x; 

Supported Tags

<input>, <keygen>, <select> and <textarea>

Browser Support

Explorer Edge Chrome Firefox Opera Safari
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung