JavaScript DHTML/Event onMethod/onChange
"onChange" Example
<head>
<script language="JavaScript">
function function2(colors) {
var col = (colors.options[colors.selectedIndex].value);
if (col) {
document.bgColor = col;
}
alert("The background color has changed to "+col)
}
</script></head>
<body>
<select name="colors" onChange="function2(this)">
<option value="white" selected>White</option>
<option value="cyan">Cyan</option>
<option value="ivory">Ivory</option>
</select>
</body>
Text field on change event
<html>
<head>
<title>Required Field</title>
<script type="text/javascript">
window.onload=setupEvents;
function setupEvents(evnt) {
document.someForm.text1.onchange = validateField;
}
function validateField(evnt) {
var theEvent = evnt ? evnt : window.event;
var target = evnt.target ? evnt.target : evnt.srcElement;
document.write(target.value);
}
</script>
</head>
<body>
<form name="someForm">
<input type="text" name="text1" /><br />
<input type="password" name="text2" /><br />
<input type="hidden" name="text3" value="hidden value" />
<textarea name="text4" cols=50 rows=10>The text area</textarea>
<input type="submit" value="Submit" />
</form>
</body>
</html>