Presidor1 commited on
Commit
fd1b35f
·
verified ·
1 Parent(s): 5b42763

Upload 3 files

Browse files
Files changed (3) hide show
  1. script.js +24 -21
  2. states-lgas.js +27 -32
  3. style.css +28 -53
script.js CHANGED
@@ -1,27 +1,30 @@
1
- document.addEventListener("DOMContentLoaded", function () {
2
- const form = document.getElementById("registrationForm");
3
 
4
- form.addEventListener("submit", async function (e) {
5
- e.preventDefault();
6
 
7
- const formData = new FormData(form);
 
 
8
 
9
- try {
10
- const response = await fetch("/submit/", {
11
- method: "POST",
12
- body: formData
13
- });
14
 
15
- if (response.ok) {
16
- const result = await response.json();
17
- alert(result.message || "Form submitted successfully!");
18
- form.reset();
19
- } else {
20
- alert("Submission failed. Please try again.");
 
 
 
 
 
 
 
21
  }
22
- } catch (error) {
23
- console.error("Error submitting form:", error);
24
- alert("An error occurred. Please try again.");
25
- }
26
- });
27
  });
 
 
 
1
 
2
+ // script.js - Handles API calls and DOM updates
 
3
 
4
+ document.addEventListener('DOMContentLoaded', function() {
5
+ const form = document.getElementById('loginForm');
6
+ const output = document.getElementById('output');
7
 
8
+ if (form) {
9
+ form.addEventListener('submit', async function(e) {
10
+ e.preventDefault();
11
+ const username = document.getElementById('username').value;
12
+ const password = document.getElementById('password').value;
13
 
14
+ output.textContent = 'Checking...';
15
+
16
+ try {
17
+ const response = await fetch('/api/check_user', {
18
+ method: 'POST',
19
+ headers: {'Content-Type': 'application/json'},
20
+ body: JSON.stringify({username, password})
21
+ });
22
+ const data = await response.json();
23
+ output.textContent = data.message || JSON.stringify(data);
24
+ } catch (error) {
25
+ console.error(error);
26
+ output.textContent = 'Error connecting to server';
27
  }
28
+ });
29
+ }
 
 
 
30
  });
states-lgas.js CHANGED
@@ -1,38 +1,33 @@
1
 
2
- const stateLGAs = {
3
- "Abia": ["Aba North", "Aba South", "Arochukwu", "Bende", "Ikwuano", "Isiala Ngwa North", "Isiala Ngwa South", "Isuikwuato", "Obi Ngwa", "Ohafia", "Osisioma", "Ugwunagbo", "Ukwa East", "Ukwa West", "Umuahia North", "Umuahia South", "Umu Nneochi"],
4
- "Adamawa": ["Demsa", "Fufore", "Ganye", "Girei", "Gombi", "Guyuk", "Hong", "Jada", "Lamurde", "Madagali", "Maiha", "Mayo-Belwa", "Michika", "Mubi North", "Mubi South", "Numan", "Shelleng", "Song", "Toungo", "Yola North", "Yola South"],
5
- "Akwa Ibom": ["Abak", "Eastern Obolo", "Eket", "Esit Eket", "Essien Udim", "Etim Ekpo", "Etinan", "Ibeno", "Ibesikpo Asutan", "Ibiono-Ibom", "Ika", "Ikono", "Ikot Abasi", "Ikot Ekpene", "Ini", "Itu", "Mbo", "Mkpat-Enin", "Nsit-Atai", "Nsit-Ibom", "Nsit-Ubium", "Obot Akara", "Okobo", "Onna", "Oron", "Oruk Anam", "Udung-Uko", "Ukanafun", "Uruan", "Urue-Offong/Oruko", "Uyo"],
6
- "Anambra": ["Aguata", "Anambra East", "Anambra West", "Anaocha", "Awka North", "Awka South", "Ayamelum", "Dunukofia", "Ekwusigo", "Idemili North", "Idemili South", "Ihiala", "Njikoka", "Nnewi North", "Nnewi South", "Ogbaru", "Onitsha North", "Onitsha South", "Orumba North", "Orumba South", "Oyi"]
7
- // You can continue to add all the other states here following the same format...
8
- };
9
 
10
- // Populate state dropdown
11
- window.onload = function () {
12
- const stateSelect = document.getElementById("state");
13
- for (const state in stateLGAs) {
14
- const option = document.createElement("option");
15
- option.value = state;
16
- option.textContent = state;
17
- stateSelect.appendChild(option);
18
- }
19
  };
20
 
21
- // Populate LGA dropdown based on selected state
22
- function populateLGAs() {
23
- const stateSelect = document.getElementById("state");
24
- const lgaSelect = document.getElementById("lga");
25
- const selectedState = stateSelect.value;
26
 
27
- // Clear existing options
28
- lgaSelect.innerHTML = '<option value="">--Select LGA--</option>';
 
 
 
 
 
29
 
30
- if (selectedState && stateLGAs[selectedState]) {
31
- stateLGAs[selectedState].forEach(lga => {
32
- const option = document.createElement("option");
33
- option.value = lga;
34
- option.textContent = lga;
35
- lgaSelect.appendChild(option);
36
- });
37
- }
38
- }
 
 
 
 
1
 
2
+ // states-lgas.js - Handles Nigerian states and LGAs dropdown population
 
 
 
 
 
 
3
 
4
+ const statesAndLgas = {
5
+ 'Lagos': ['Ikeja', 'Epe', 'Ikorodu'],
6
+ 'Kano': ['Nasarawa', 'Tarauni', 'Dala'],
7
+ 'FCT': ['Gwagwalada', 'Abaji', 'Bwari'],
 
 
 
 
 
8
  };
9
 
10
+ document.addEventListener('DOMContentLoaded', function() {
11
+ const stateSelect = document.getElementById('state');
12
+ const lgaSelect = document.getElementById('lga');
 
 
13
 
14
+ if (stateSelect && lgaSelect) {
15
+ for (const state in statesAndLgas) {
16
+ const option = document.createElement('option');
17
+ option.value = state;
18
+ option.textContent = state;
19
+ stateSelect.appendChild(option);
20
+ }
21
 
22
+ stateSelect.addEventListener('change', function() {
23
+ const lgas = statesAndLgas[this.value] || [];
24
+ lgaSelect.innerHTML = '';
25
+ lgas.forEach(lga => {
26
+ const option = document.createElement('option');
27
+ option.value = lga;
28
+ option.textContent = lga;
29
+ lgaSelect.appendChild(option);
30
+ });
31
+ });
32
+ }
33
+ });
style.css CHANGED
@@ -1,64 +1,39 @@
1
 
 
2
  body {
3
- font-family: Arial, sans-serif;
4
- margin: 0;
5
- padding: 0;
6
- background: #f4f4f9;
7
- color: #333;
8
- }
9
- header {
10
- background: #005792;
11
- color: white;
12
- padding: 1rem;
13
- text-align: center;
14
- }
15
- nav ul {
16
- list-style: none;
17
- display: flex;
18
- justify-content: center;
19
- padding: 0;
20
- }
21
- nav ul li {
22
- margin: 0 15px;
23
- }
24
- nav ul li a {
25
- color: white;
26
- text-decoration: none;
27
- }
28
- .hero {
29
- padding: 2rem;
30
- background: #d1e7ff;
31
- text-align: center;
32
- }
33
- .form-section, .info-section {
34
- padding: 2rem;
35
  }
 
36
  form {
37
- max-width: 600px;
 
 
 
38
  margin: auto;
39
- display: flex;
40
- flex-direction: column;
41
  }
42
- form label {
43
- margin: 10px 0 5px;
44
- }
45
- form input, form select {
46
- padding: 10px;
47
- font-size: 1rem;
 
48
  }
49
- form button {
50
- margin-top: 15px;
51
- padding: 10px;
52
- font-size: 1rem;
53
- background-color: #005792;
54
  color: white;
55
  border: none;
56
- cursor: pointer;
57
- border-radius: 5px;
58
  }
59
- footer {
60
- text-align: center;
61
- padding: 1rem;
62
- background: #333;
63
- color: white;
 
 
 
64
  }
 
1
 
2
+ /* style.css - Basic styling */
3
  body {
4
+ font-family: sans-serif;
5
+ padding: 20px;
6
+ background: #f5f5f5;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  }
8
+
9
  form {
10
+ background: #fff;
11
+ padding: 15px;
12
+ border-radius: 8px;
13
+ max-width: 300px;
14
  margin: auto;
15
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
 
16
  }
17
+
18
+ input, select, button {
19
+ width: 100%;
20
+ padding: 8px;
21
+ margin: 5px 0;
22
+ border-radius: 5px;
23
+ border: 1px solid #ddd;
24
  }
25
+
26
+ button {
27
+ background: #007bff;
 
 
28
  color: white;
29
  border: none;
 
 
30
  }
31
+
32
+ button:hover {
33
+ background: #0056b3;
34
+ }
35
+
36
+ #output {
37
+ margin-top: 10px;
38
+ font-weight: bold;
39
  }