-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha4-2.html
76 lines (67 loc) · 2.6 KB
/
a4-2.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="#" method="post" id="demoForm" class="demoForm">
<fieldset>
<legend>Demo: Get Value or Text of Selected Option</legend>
<p>
<select id="scripts" name="scripts">
<option value="scroll">Scrolling Divs JavaScript</option>
<option value="tooltip">JavaScript Tooltips</option>
<option value="con_scroll">Continuous Scroller</option>
<option value="banner">Rotating Banner JavaScript</option>
<option value="random_img">Random Image PHP</option>
<option value="form_builder">PHP Form Generator</option>
<option value="table_class">PHP Table Class</option>
<option value="order_forms">PHP Order Forms</option>
</select>
<input type="text" size="30" name="display" id="display" />
</p>
<p>
<input type="button" id="showVal" value="Value Property" />
<input type="button" id="showTxt" value="selectedIndex/Text" />
<input type="button" id="doLoop" value="Value from Loop" />
</p>
</fieldset>
</form>
<script>
// get references to select list and display text box
var sel = document.getElementById("scripts");
var el = document.getElementById("display");
// console.log(sel);
// console.log(el);
function getSelectedOption(sel) {
var opt;
for (var i = 0, len = sel.options.length; i < len; i++) {
opt = sel.options[i];
// console.log("option"+(i+1)+':');
// console.log(opt.selected);
// console.log(opt)
if (opt.selected === true) {
break;
}
}
return opt;
}
// assign onclick handlers to the buttons
document.getElementById("showVal").onclick = function() {
el.value = sel.value;
};
document.getElementById("showTxt").onclick = function() {
// access text property of selected option
el.value = sel.options[sel.selectedIndex].text;
};
document.getElementById("doLoop").onclick = function() {
var opt = getSelectedOption(sel);
console.log('doLoop_opt:');
console.log(opt);
el.value = opt.value;
};
</script>
</body>
</html>