-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
154 lines (99 loc) · 4.28 KB
/
main.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
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
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
document.getElementById("currentYear").textContent = currentYear;
document.addEventListener("DOMContentLoaded", function () {
// Fetch and populate divisions
const divisionSelect = document.getElementById('division');
fetch('divisions.json')
.then(response => response.json())
.then(data => {
data[2].data.forEach(division => {
const option = document.createElement('option');
option.value = division.name;
option.text = division.name;
option.id = division.id;
divisionSelect.appendChild(option);
});
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
// Event listener for District select
const districtSelect = document.getElementById('district');
divisionSelect.addEventListener('change', function () {
// Clear existing districts (except the default option)
while (districtSelect.options.length > 1) {
districtSelect.remove(1);
}
const selectedOption = divisionSelect.options[divisionSelect.selectedIndex];
const divisionID = selectedOption.getAttribute('id');
// Fetch and populate districts based on the selected division
fetch('districts.json')
.then(response => response.json())
.then(data => {
const matchingDistricts = data[2].data.filter(district => district.division_id === divisionID);
matchingDistricts.forEach(district => {
const option = document.createElement('option');
option.value = district.name;
option.text = district.name;
option.id = district.id;
districtSelect.appendChild(option);
});
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
// Event listener for Upazila select
const upazilaSelect = document.getElementById('upazila');
districtSelect.addEventListener('change', function () {
// Clear existing upazilas (except the default option)
while (upazilaSelect.options.length > 1) {
upazilaSelect.remove(1);
}
const selectedOption = districtSelect.options[districtSelect.selectedIndex];
const districtD = selectedOption.getAttribute('id');
// Fetch and populate upazilas based on the selected division
fetch('upazilas.json')
.then(response => response.json())
.then(data => {
const matchingupazilas = data[2].data.filter(upazila => upazila.district_id === districtD);
matchingupazilas.forEach(upazila => {
const option = document.createElement('option');
option.value = upazila.name;
option.text = upazila.name;
option.id = upazila.id;
upazilaSelect.appendChild(option);
});
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
// Event listener for union select
const unionSelect = document.getElementById('union');
upazilaSelect.addEventListener('change', function () {
// Clear existing unions (except the default option)
while (unionSelect.options.length > 1) {
unionSelect.remove(1);
}
const selectedOption = upazilaSelect.options[upazilaSelect.selectedIndex];
const upazillaID = selectedOption.getAttribute('id');
// Fetch and populate unions based on the selected division
fetch('unions.json')
.then(response => response.json())
.then(data => {
const matchingUnions = data[2].data.filter(union => union.upazilla_id === upazillaID);
matchingUnions.forEach(union => {
const option = document.createElement('option');
option.value = union.name;
option.text = union.name;
option.id = union.id;
unionSelect.appendChild(option);
});
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
})
});
})
})