HTML | DOM onchange Event
The HTML DOM onchange event occurs when the value of an element has been changed. It also works with radio buttons and checkboxes when the checked state has been changed.
Note: This event is similar to the oninput event but the only difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.
Syntax:
In HTML:
<element onchange="myScript">
In JavaScript:
object.onchange = function(){myScript};
In JavaScript, using the addEventListener() method:
object.addEventListener("change", myScript);
Example: Using HTML
<!DOCTYPE html> <html> <body> <center> <h1 style="color:green"> GeeksforGeeks </h1> <h2>HTML DOM onchange Event</h2> <select id="LangSelect" onchange="GFGfun()"> <option value="c">C</option> <option value="java">JAVA</option> <option value="html">HTML</option> <option value="python">PYTHON</option> </select> <p id="demo"></p> <script> function GFGfun() { var x = document.getElementById("LangSelect").value; document.getElementById( "demo").innerHTML = "You selected: " + x; } </script> </center> </body> </html> |
Output:
Before:

After:

Example: Using JavaScript
<!DOCTYPE html> <html> <body> <center> <h1 style="color:green"> GeeksforGeeks </h1> <h2>HTML DOM onchange Event</h2> Email: <input type="email" id="email"> <script> document.getElementById( "email").onchange = function() { GFGfun() }; function GFGfun() { var x = document.getElementById("email"); x.value = x.value.toLowerCase(); } </script> </center> </body> </html> |
Output:
Before:

After:

Example: In JavaScript, using the addEventListener() method:
<!DOCTYPE html> <html> <body> <center> <h1 style="color:green"> GeeksforGeeks </h1> <h2>HTML DOM onchange Event</h2> Email: <input type="email" id="email"> <script> document.getElementById( "email").addEventListener( "change", GFGfun); function GFGfun() { var x = document.getElementById("email"); x.value = x.value.toLowerCase(); } </script> </center> </body> </html> |
Before:

After:

Supported Browsers: The browsers supported by DOM onchange Event are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Apple Safari
- Opera
Recommended Posts:
- HTML | onchange Event Attribute
- How to trigger onchange event on input type=range while dragging in Firefox ?
- HTML | DOM touchend Event
- HTML | DOM onloadedmetadata Event
- HTML | DOM onloadeddata Event
- HTML | DOM onkeydown Event
- HTML | DOM oncanplay Event
- HTML | DOM onload Event
- HTML | DOM oncanplaythrough Event
- HTML | DOM ontoggle Event
- HTML | DOM onkeyup Event
- HTML | DOM onkeypress Event
- HTML | DOM onblur Event
- HTML | DOM ondrop Event
- HTML | DOM ondragend Event
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



