html tutorial - onchange Attribute in HTML - html5 - html code - html form

Learn html - html tutorial - Onchange attribute in html - html examples - html programs
- The onchange attribute trigger an event when the value of the element is changed.
- The onchange attribute is a section of the Event Attributes.
Syntax for onchange attribute in HTML:
<element onchange="script" >
Applies To:
Element | Attribute |
---|---|
All HTML Elements | onchange |
onchange Attribute Value:
Value | Description |
---|---|
script | The script can run on onchange. |
Sample Coding for onchange Attribute in HTML:
Tryit<!DOCTYPE html>
<html>
<head>
<title>Wikitechy onchange attribute</title>
</head>
<body>
Select Wikitechy Tutorial :<br><br>
<select name="tutorial" onchange="onChange(this.value)">
<option value="HTML">Wikitechy HTML</option>
<option value="CSS">Wikitechy CSS</option>
<option value="PHP">Wikitechy PHP</option>
</select>
<script>
function onChange(val) {
alert("The Value Changed as : " + val);
}
</script>
</body>
</html>
Code Explanation for onchange Attribute in HTML:

- onchange attribute used to call the onChange JavaScript function when the drop-down list value changed.
- The onChange JavaScript function display an alert message with the selected value.
Output for onchange Attribute in HTML:

- The output shows the drop-down list and user try to change the value.
- When user try to change the value HTML to PHP the alert box show an message as “The Value Changed as : PHP”

Browser Support for onchange Attribute in HTML:
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
Tips and Notes
- The onchange event is similar to the oninput event.
- The difference is which the oninput event shows suddenly after the value of an element has changed, although onchange event shows when the element drops focus.