Update script.js
Browse files
script.js
CHANGED
|
@@ -1,57 +1,63 @@
|
|
| 1 |
document.addEventListener("DOMContentLoaded", function () {
|
| 2 |
-
//
|
| 3 |
const stateSelect = document.getElementById("state");
|
| 4 |
const lgaSelect = document.getElementById("lga");
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
const
|
| 10 |
-
|
| 11 |
-
lgas.forEach(lga => {
|
| 12 |
const option = document.createElement("option");
|
| 13 |
-
option.value =
|
| 14 |
-
option.textContent =
|
| 15 |
-
|
| 16 |
-
});
|
| 17 |
-
});
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
// --- Handle passport image preview and storage ---
|
| 21 |
-
const passportInput = document.getElementById("passport");
|
| 22 |
-
if (passportInput) {
|
| 23 |
-
passportInput.addEventListener("change", function () {
|
| 24 |
-
const file = this.files[0];
|
| 25 |
-
if (file) {
|
| 26 |
-
const reader = new FileReader();
|
| 27 |
-
reader.onload = function (e) {
|
| 28 |
-
localStorage.setItem("stcPassportPhoto", e.target.result);
|
| 29 |
-
};
|
| 30 |
-
reader.readAsDataURL(file);
|
| 31 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
});
|
| 33 |
-
}
|
| 34 |
|
| 35 |
-
//
|
| 36 |
-
const form = document.
|
| 37 |
if (form) {
|
| 38 |
form.addEventListener("submit", function (e) {
|
| 39 |
e.preventDefault();
|
| 40 |
|
| 41 |
-
const
|
| 42 |
-
fullname:
|
| 43 |
-
email:
|
| 44 |
-
phone:
|
| 45 |
-
gender:
|
| 46 |
-
religion:
|
| 47 |
-
state:
|
| 48 |
-
lga:
|
| 49 |
-
address:
|
| 50 |
-
note:
|
| 51 |
};
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
});
|
| 56 |
}
|
| 57 |
});
|
|
|
|
| 1 |
document.addEventListener("DOMContentLoaded", function () {
|
| 2 |
+
// Load States and LGAs
|
| 3 |
const stateSelect = document.getElementById("state");
|
| 4 |
const lgaSelect = document.getElementById("lga");
|
| 5 |
|
| 6 |
+
fetch("states-lgas.js")
|
| 7 |
+
.then(response => response.text())
|
| 8 |
+
.then(data => {
|
| 9 |
+
const stateData = eval(data); // Convert into object
|
| 10 |
+
for (let state in stateData) {
|
|
|
|
| 11 |
const option = document.createElement("option");
|
| 12 |
+
option.value = state;
|
| 13 |
+
option.textContent = state;
|
| 14 |
+
stateSelect.appendChild(option);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
| 16 |
+
|
| 17 |
+
stateSelect.addEventListener("change", function () {
|
| 18 |
+
const selected = this.value;
|
| 19 |
+
lgaSelect.innerHTML = "<option value=''>Select LGA</option>";
|
| 20 |
+
if (stateData[selected]) {
|
| 21 |
+
stateData[selected].forEach(lga => {
|
| 22 |
+
const lgaOption = document.createElement("option");
|
| 23 |
+
lgaOption.value = lga;
|
| 24 |
+
lgaOption.textContent = lga;
|
| 25 |
+
lgaSelect.appendChild(lgaOption);
|
| 26 |
+
});
|
| 27 |
+
}
|
| 28 |
+
});
|
| 29 |
});
|
|
|
|
| 30 |
|
| 31 |
+
// Form Submission Save to Local Storage
|
| 32 |
+
const form = document.querySelector("form");
|
| 33 |
if (form) {
|
| 34 |
form.addEventListener("submit", function (e) {
|
| 35 |
e.preventDefault();
|
| 36 |
|
| 37 |
+
const userData = {
|
| 38 |
+
fullname: form.fullname.value,
|
| 39 |
+
email: form.email.value,
|
| 40 |
+
phone: form.phone.value,
|
| 41 |
+
gender: form.gender.value,
|
| 42 |
+
religion: form.religion.value,
|
| 43 |
+
state: form.state.value,
|
| 44 |
+
lga: form.lga.value,
|
| 45 |
+
address: form.address.value,
|
| 46 |
+
note: form.note.value
|
| 47 |
};
|
| 48 |
|
| 49 |
+
const passportFile = form.passport.files[0];
|
| 50 |
+
if (passportFile) {
|
| 51 |
+
const reader = new FileReader();
|
| 52 |
+
reader.onloadend = function () {
|
| 53 |
+
localStorage.setItem("stcPassportPhoto", reader.result);
|
| 54 |
+
localStorage.setItem("stcApplication", JSON.stringify(userData));
|
| 55 |
+
window.location.href = "success.html";
|
| 56 |
+
};
|
| 57 |
+
reader.readAsDataURL(passportFile);
|
| 58 |
+
} else {
|
| 59 |
+
alert("Please upload your passport photo.");
|
| 60 |
+
}
|
| 61 |
});
|
| 62 |
}
|
| 63 |
});
|