jQuery change event
In this section, you will learn about jQuery change event. jQuery provides change event this is similar as javascript onchange event.
change event: The change jquery change event is very similar to onchange event. Change event is applied on combo box or select box. When you select diffrent value in combo for each selection then change event is fired.
Following example you will see the change event handler with running example.
The click handler:
Running Example for change event:
<html>
<head>
<title>jQuery change event, jquery select change</title>
<script type="text/javascript" language="javascript"
src="../scripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready ( function(){
$('select#course').change(function(){
var selectedCourse = $('select#course').val();
alert(selectedCourse);
$('div#setCourse').html(selectedCourse);
})
});
</script>
</head>
<body>
<h1>Change Event Example</h1>
Please select:
<select name="course" id="course">
<option value="MCA">MCA</option>
<option value="BCA">BCA</option>
<option value="DCA">DCA</option>
<option value="PGDCA">PGDCA</option>
<option value="MBA">MBA</option>
<option value="BBA">BBA</option>
</select>
<br><br><br><br>
You are in <b><div id="setCourse"></div></b>
</body>
</html>
|
If you want to try it then you click on bellow link and test it.
Try online