-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
102 lines (95 loc) · 2.13 KB
/
demo.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>jQuery Chained Selects Demo</title>
<style type="text/css">
.container {
width: 70%;
margin: 0 auto;
}
form {
margin: 10px;
}
select {
width: 100%;
font-size: 1.5em;
padding: 10px;
margin: 4px 0;
}
textarea {
width: 100%;
min-height: 500px;
margin: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Form Example</h2>
<form method="post" action="https://httpbin.org/post">
<button type="submit">Submit</button>
<strong id="selected">current</strong>
</form>
<h2>Test your JSON Data</h2>
<textarea id="json">{
"A": {
"AA": {
"1": "AAA"
},
"AB": {
"2": "ABA"
}
},
"B": {
"BA": {
"BAA": {
"3": "BAAA"
}
}
},
"C": {
"CA": {
"4": "CAA"
},
"CB": {
"5": "CBA"
},
"CC": {
"CCA": {
"6": "CCAA",
"7": "CCAB"
}
}
}
}</textarea>
<button id="load_json">Load JSON</button>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="jquery.chained.selects.js"></script>
<script type="text/javascript">
var chainedData = {};
function loadJson() {
$("form select").remove();
$("<select name=\"example_select\" id=\"example-select\"></select>").insertBefore("form button");
chainedData = JSON.parse($("#json").val());
$('#example-select').chainedSelects({
data: chainedData,
loggingEnabled: true,
onSelectedCallback: function (id) {
if (console !== undefined) {
console.log("selected option", id);
}
$("#selected").text("selected option: " + id);
},
});
}
$(document).ready(function () {
$("#load_json").click(loadJson);
loadJson();
});
</script>
</body>
</html>