Quick Reach
jQuery select change
In the previous chapter, we learned the change event in jQuery with text box example. Below is an example of using change event on the select element of HTML.
In this example, as a value from the select box is selected, the change event will occur. As change event occurs, the change() method of jQuery will be used to show an alert with selected value from the dropdown.
Experience this example online
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<html>
<head>
<script src=“http://code.jquery.com/jquery-1.10.1.min.js”></script>
<script>
$(document).ready(function(){
$(“#sel_change”).change(function(){
alert (“change event occured with value: “ + document.getElementById(“sel_change”).value);
});
});
</script>
</head>
<body>
<p>Select a menu item to see change event!</p>
<form id=“changeform”>
select a value from dropdown:
<select id=“sel_change”>
<option value=“Jan”>Jan</option>
<option value=“Feb”>Feb</option>
<option value=“March”>Mar</option>
<option value=“April”>Apr</option>
</select>
</form>
</body>
</html>
|
Leave A Comment?