Presidor1 commited on
Commit
0bda54e
·
verified ·
1 Parent(s): 3c46ef0

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +46 -40
script.js CHANGED
@@ -1,57 +1,63 @@
1
  document.addEventListener("DOMContentLoaded", function () {
2
- // --- Handle state-LGA dynamic linking ---
3
  const stateSelect = document.getElementById("state");
4
  const lgaSelect = document.getElementById("lga");
5
 
6
- if (stateSelect && lgaSelect) {
7
- stateSelect.addEventListener("change", function () {
8
- const selectedState = this.value;
9
- const lgas = statesLGAs[selectedState] || [];
10
- lgaSelect.innerHTML = "<option value=''>Select LGA</option>";
11
- lgas.forEach(lga => {
12
  const option = document.createElement("option");
13
- option.value = lga;
14
- option.textContent = lga;
15
- lgaSelect.appendChild(option);
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
- // --- Form submission handler ---
36
- const form = document.getElementById("registration-form");
37
  if (form) {
38
  form.addEventListener("submit", function (e) {
39
  e.preventDefault();
40
 
41
- const formData = {
42
- fullname: document.getElementById("fullname").value,
43
- email: document.getElementById("email").value,
44
- phone: document.getElementById("phone").value,
45
- gender: document.getElementById("gender").value,
46
- religion: document.getElementById("religion").value,
47
- state: document.getElementById("state").value,
48
- lga: document.getElementById("lga").value,
49
- address: document.getElementById("address").value,
50
- note: document.getElementById("note").value,
51
  };
52
 
53
- localStorage.setItem("stcApplication", JSON.stringify(formData));
54
- window.location.href = "success.html";
 
 
 
 
 
 
 
 
 
 
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
  });