The onchange event occurs when a select input element has a selection made or when a text input element has a change in the text. Whenever the select or change occurs, the script code associated with the onselect event is executed. This script can call JavaScript functions which contain code that you want to run when the select occurs.
These six events are useful when dealing with forms and form elements:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru XHTML onchange Example</title>
</head>
<body>
<form>
Please make a selection.
<br />
Note that an alert appears every time that you make a new selection.
<br />
<select onchange="JavaScript:alert('A new selection has been made')">
<option>Angel fish</option>
<option>Cat fish</option>
<option>Discus</option>
<option>Neon tetra</option>
</select>
</p>
</form>
</body>
</html>
In this example, an alert message appears when a select is made.