-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (30 loc) · 1.25 KB
/
Copy pathscript.js
File metadata and controls
35 lines (30 loc) · 1.25 KB
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
document.addEventListener("DOMContentLoaded", function () {
// Select all state and district dropdowns
const allStateSelects = document.querySelectorAll("#state");
const allDistrictSelects = document.querySelectorAll("#district");
// Initialize each state/district pair
allStateSelects.forEach((stateSelect, index) => {
const districtSelect = allDistrictSelects[index];
// Populate states
Object.keys(statesAndDistricts).forEach((state) => {
const option = document.createElement("option");
option.value = state;
option.textContent = state;
stateSelect.appendChild(option);
});
// Populate districts when state changes
stateSelect.addEventListener("change", function () {
const selectedState = this.value;
// Clear previous districts
districtSelect.innerHTML = '<option value="">--Select District--</option>';
if (selectedState && statesAndDistricts[selectedState]) {
statesAndDistricts[selectedState].forEach((district) => {
const option = document.createElement("option");
option.value = district;
option.textContent = district;
districtSelect.appendChild(option);
});
}
});
});
});