forked from ehynds/jquery-related-selects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.htm
216 lines (176 loc) · 6.3 KB
/
index.htm
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>jQuery Related Selects</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="src/jquery.relatedselects.min.js" type="text/javascript"></script>
<style type="text/css">
body { font:12px helvetica, arial, sans-serif; }
</style>
<script type="text/javascript">
$(function(){
$("#example-1, #example-3").relatedSelects({
onChangeLoad: 'datasupplier.php',
defaultOptionText: 'Choose an Option',
selects: {
'stateID': { loadingMessage:'Loading Counties...' },
'countyID': { loadingMessage:'Loading Towns...' },
'townID': { loadingMessage:'Loading Villages...' },
'villageID': {}
}
});
$("#example-2").relatedSelects({
onChangeLoad: 'datasupplier.php',
loadingMessage: 'Please wait',
selects: ['stateID', 'countyID', 'townID', 'villageID']
});
$("#example-4").relatedSelects({
onChangeLoad: 'datasupplier.php',
selects: ['stateID', 'countyID']
});
$("#example-5").relatedSelects({
onChangeLoad: 'datasupplier.php',
selects: ['stateID', 'countyID'],
onChange: function(){
// 'this' is a reference to the changed select box
alert( $(this).attr('name') + ' changed!');
},
onLoadingStart: function(){
// 'this' is a reference to the sibling select box that just had data loaded into it.
$(this).siblings('div').html("Loading, please wait...");
},
onLoadingEnd: function(){
// 'this' is a reference to the sibling select box that just had data loaded into it.
$(this).siblings('div').html("Please choose an option above.");
}
});
$("#example-6").relatedSelects({
onChangeLoad: 'datasupplier.php',
loadingMessage: 'Please wait',
selects: ['stateID', 'countyID','townID'],
disableIfEmpty:true,
onEmptyResult: function(){
// 'this' is a reference to the changed select box
alert('Unable to find any matches for ' + $(this).find('option:selected').text() + '!');
}
});
$("#example-7").relatedSelects({
onChangeLoad: 'datasupplier.htm',
dataType: 'html',
selects: ['stateID', 'countyID']
});
});
</script>
</head>
<body>
<h1>jQuery Related Selects Plugin</h1>
<ul>
<li><a href="http://github.com/ehynds/jquery-related-selects">Documentation & download</a> at GitHub</li>
<li>My original <a href="http://www.erichynds.com/jquery/jquery-related-dependent-selects-plugin/">blog post and comments</a></li>
</ul>
<p>Note that in examples 1-6, the file that supplies the data <b>pauses for 1 second</b> so you can see the loading messages.</p>
<h2>Example 1</h2>
<p>The state select is pre-populated, and the rest will populate based on preceding values. Each select is configured with a custom loading message, and the default option text is set to "Choose an Option".</p>
<form id="example-1">
<select name="stateID">
<option value="">Choose State »</option>
<option value="MA">Massachusetts</option>
<option value="VT">Vermont</option>
</select>
<select name="countyID">
<option value="">Choose County »</option>
</select>
<select name="townID">
<option value="">Choose Town »</option>
</select>
<select name="villageID">
<option value="">Choose Village »</option>
</select>
</form>
<h2>Example 2</h2>
<p>The state and county selects are pre-populated and legitimate values are selected. Since the 'County' select already has a selected option,
the 'Town' select automatically populates. Individual selects do not have any custom settings. No defaultOptionText override.</p>
<form id="example-2">
<select name="stateID">
<option value="">Choose State »</option>
<option value="MA" selected="selected">Massachusetts</option>
<option value="VT">Vermont</option>
</select>
<select name="countyID">
<option value="">Choose County »</option>
<option value="BARN" selected="selected">Barnstable</option>
</select>
<select name="townID">
<option value="">Choose Town »</option>
</select>
<select name="villageID">
<option value="">Choose Village »</option>
</select>
</form>
<h2>Example 3</h2>
<p>The state select is populated, and the HTML structure of the other three are completely empty when the page loads.</p>
<form id="example-3">
<select name="stateID">
<option value="">Choose State »</option>
<option value="MA">Massachusetts</option>
<option value="VT">Vermont</option>
</select>
<select name="countyID"></select>
<select name="townID"></select>
<select name="villageID"></select>
</form>
<h2>Example 4</h2>
<p>Basic, just two selects.</p>
<form id="example-4">
<select name="stateID">
<option value="">Choose State »</option>
<option value="MA">Massachusetts</option>
<option value="VT">Vermont</option>
</select>
<select name="countyID">
<option value="">Choose County »</option>
</select>
</form>
<h2>Example 5</h2>
<p>Using the onChange, onLoadingStart & onLoadingEnd callbacks.</p>
<form id="example-5">
<select name="stateID">
<option value="">Choose State »</option>
<option value="MA">Massachusetts</option>
<option value="VT">Vermont</option>
</select>
<select name="countyID">
<option value="">Choose County »</option>
</select>
<div><!-- placeholder for our callback message --></div>
</form>
<h2>Example 6</h2>
<p>Using the DisableIfEmpty option & the onEmptyResult callback.</p>
<form id="example-6">
<select name="stateID">
<option value="">Choose State »</option>
<option value="TX">Texas</option>
<option value="SC">South Carolina</option>
</select>
<select name="countyID">
<option value="">Choose County »</option>
</select>
<select name="townID">
<option value="">Choose Town »</option>
</select>
<div></div>
</form>
<h2>Example 7</h2>
<p>Retreiving data in HTML format instead of JSON. This option gives you more control of the options, like the ability to add optgroups. <a href="datasupplier.htm">View the data file.</a></p>
<form id="example-7">
<select name="stateID">
<option value="">Choose State »</option>
<option value="CA">California</option>
</select>
<select name="countyID">
<option value="">Choose County »</option>
</select>
</form>
</body>
</html>