-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectboxExample01.htm
More file actions
executable file
·50 lines (45 loc) · 1.98 KB
/
Copy pathSelectboxExample01.htm
File metadata and controls
executable file
·50 lines (45 loc) · 1.98 KB
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
48
49
50
<!DOCTYPE html>
<html>
<head>
<title>Selectbox Example</title>
<script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
<form method="post" action="javascript:alert('Form submitted!')" id="myForm">
<div>
<label for="selLocation">Where do you want to live?</label>
<select name="location" id="selLocation">
<option value="Sunnyvale, CA">Sunnyvale</option>
<option value="Los Angeles, CA">Los Angeles</option>
<option value="Mountain View, CA">Mountain View</option>
<option value="">China</option>
<option>Australia</option>
</select>
</div>
<div>
<input type="button" value="Select first option" id="btnFirst" />
<input type="button" value="Select second option" id="btnSecond" />
<input type="button" value="Get selected option" id="btnSelected" />
</div>
</form>
<script type="text/javascript">
(function(){
var btn1 = document.getElementById("btnFirst"),
btn2 = document.getElementById("btnSecond"),
btn3 = document.getElementById("btnSelected"),
selectbox = document.getElementById("selLocation");
EventUtil.addHandler(btn1, "click", function(event){
selectbox.selectedIndex = 0;
});
EventUtil.addHandler(btn2, "click", function(event){
selectbox.selectedIndex = 1;
});
EventUtil.addHandler(btn3, "click", function(event){
var selIndex = selectbox.selectedIndex;
var selOption = selectbox.options[selIndex];
alert("Selected index: " + selectbox.selectedIndex + "\nSelected text: " + selOption.text + "\nSelected value: " + selOption.value);
});
})();
</script>
</body>
</html>