-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
29 lines (24 loc) · 839 Bytes
/
index.js
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
// `data` should be filled with provinces and their cities in json format
$(document).ready(function() {
$('.ir-province').each(loadProvinces);
$('.ir-province').change(loadCities);
});
var loadProvinces = function() {
var element = $(this);
element.empty();
element.append($('<option></option>').attr('value', 'empty'));
$.each(data, function(province, list) {
var option = $('<option></option>').attr('value', province).text(province);
element.append(option);
});
};
var loadCities = function() {
var citySelector = $(this).closest('div.ir-select').find('.ir-city');
var selectedProvince = $(this).val();
var cityList = data[selectedProvince];
citySelector.empty();
$.each(cityList, function(index, city) {
var option = $('<option></option>').attr('value', city).text(city);
citySelector.append(option);
});
};