Execute a JavaScript when a user changes the selected option of a <select> element:
More "Try it Yourself" examples below.
The onchange attribute fires the moment when the value of the element is changed.
Tip: 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, while onchange occurs when the element loses focus. The other difference is that the onchange event also works on <keygen> and <select> elements.
Event Attribute | |||||
---|---|---|---|---|---|
onchange | Yes | Yes | Yes | Yes | Yes |
None.
Value | Description |
---|---|
script | The script to be run on onchange |
Supported HTML tags: | <input type="checkbox">, <input type="file">, <input type="password">, <input type="radio">, <input type="range">, <input type="search">, <input type="text">, <keygen>, <select> and <textarea> |
---|
Execute a JavaScript when the user changes the content of an input field:
HTML DOM reference: onchange event