-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo_multiple.html
115 lines (103 loc) · 2.55 KB
/
demo_multiple.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
102
103
104
105
106
107
108
109
110
111
112
113
114
<!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">
<div id="firstChain" style="border: 3px solid black; margin-bottom: 2rem; background-color: grey;">
<h3>First Chain</h3>
</div>
<div id="secondChain" style="border: 3px solid black; margin-bottom: 2rem; background-color: lightblue;">
<h3>Second Chain</h3>
</div>
<button type="submit">Submit</button>
</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.3.1.min.js"></script>
<script src="jquery.chained.selects.js"></script>
<script type="text/javascript">
var chainedData1 = {};
var chainedData2 = {};
function loadJson() {
$("form select").remove();
$("#firstChain").append($("<select name=\"example1\" id=\"example1\"></select>"));
$("#secondChain").append($("<select name=\"example2\" id=\"example2\"></select>"));
chainedData1 = JSON.parse($("#json").val());
chainedData2 = JSON.parse($("#json").val());
$('#example1').chainedSelects({
data: chainedData1,
loggingEnabled: true,
'onSelectedCallback': function (id) { if(console !== undefined) { console.log("chain1 selected option", id); } },
});
$('#example2').chainedSelects({
data: chainedData2,
loggingEnabled: true,
'onSelectedCallback': function (id) { if(console !== undefined) { console.log("chain2 selected option", id); } },
});
}
$(document).ready(function () {
$("#load_json").click(loadJson);
loadJson();
});
</script>
</body>
</html>