The onchange
attribute event is triggered
when the value of the element is changed.
None.
<element onchange="script or Javascript function name">
<input type="checkbox">, <input type="file">, <input type="password">, <input type="radio">, <input type="range">, <input type="search">, <input type="text">, <keygen>, <select> <textarea>
onchange |
Yes | Yes | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<body>
<!-- ww w. j a v a2 s . co m-->
<select id="mySelect" onchange="myFunction()">
<option value="CSS">CSS</option>
<option value="HTML">HTML</option>
<option value="Javascript">Javascript</option>
<option value="SQL">SQL</option>
</select>
<script>
function myFunction() {
alert(document.getElementById("mySelect").value);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<!-- w ww . j a va 2 s . c o m-->
Enter some text:
<input type="text" name="txt" value="Hello" onchange="myFunction(this.value)">
<input type="text" name="txt2" value="Hello another" onchange="myFunction(this.value)">
<script>
function myFunction(val) {
alert(val);
}
</script>
<p>Edit text and tab out.</p>
</body>
</html>