-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
82 lines (73 loc) · 2.74 KB
/
script.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
// Division / District / Upazila onload function
window.onload = function () {
var divisionSelect = document.getElementById("division");
var districtSelect = document.getElementById("district");
var upazilaSelect = document.getElementById("upazila");
var countryData =
"https://gist.githubusercontent.com/dizaraj/7a8a4b51c6c4dfe3400dc3203f7025fe/raw/bdinfo.json";
fetch(countryData)
.then((response) => response.json())
.then((data) => {
// Populate the division select element
// console.log(data["Chittagong"]["Chittagong"]["Anwara"]);
for (var division in data) {
// console.log(division);
var option = document.createElement("option");
option.text = division;
option.value = division;
divisionSelect.add(option);
}
// Update the district and upazila select elements when a division is selected
divisionSelect.onchange = function () {
// Clear the district and upazila select elements
selectedDivision = this.value;
districtSelect.length = 1;
upazilaSelect.length = 1;
// Populate the district select element
var districts = data[this.value];
for (var district in districts) {
// console.log(district);
var option = document.createElement("option");
option.text = district;
option.value = district;
districtSelect.add(option);
}
};
// Update the upazila select element when a district is selected
districtSelect.onchange = function () {
// Clear the upazila select element
upazilaSelect.length = 1;
// Populate the upazila select element
var upazilas = data[selectedDivision][this.value];
if (Array.isArray(upazilas)){
for (var upazila of upazilas) {
var option = document.createElement("option");
option.text = upazila;
option.value = upazila;
upazilaSelect.add(option);
}
}
else{
for (var upazila in upazilas) {
var option = document.createElement("option");
option.text = upazila;
option.value = upazila;
upazilaSelect.add(option);
}
}
};
})
.catch((error) => console.error("Error:", error));
};
function fetchAllHtml(id, htmlFile) {
fetch(htmlFile)
.then((response) => response.text())
.then((data) => (document.getElementById(id).innerHTML = data))
.catch((error) => console.error(error));
}
// List of HTML files in the 'body_parts' folder
var htmlFiles = ["header", "hero", "cta", "footer", "request"];
// Fetch each HTML file
htmlFiles.forEach((file) => {
fetchAllHtml(file, `./assets/body_parts/${file}.html`);
});