-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
204 lines (177 loc) · 5.78 KB
/
index.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CPAN134 WEB - EXERCISE 2</title>
<link rel="stylesheet" href="styles.css" />
<link rel="stylesheet" href="crt.css" />
<script defer src="script.js"></script>
</head>
<body class="crt">
<div class="bodyContent">
<header style="text-align: center">
<h1>**** CPAN134 WEB - EXERCISE 2 ****</h1>
<p aria-label="System RAM info">
134K RAM SYSTEM 2025 BASIC BYTES FREE
</p>
</header>
<main>
<form
id="exer02form"
action="#"
method="POST"
aria-labelledby="form-title"
>
<h2 id="form-title">Registration Form</h2>
<div>
<label for="name">Full Name:</label>
<input
type="text"
id="name"
name="name"
required
aria-required="true"
aria-describedby="name-desc"
/>
<p id="name-desc" class="sr-only">Enter your full legal name</p>
</div>
<br />
<div>
<label for="email">Email Address:</label>
<input
type="email"
id="email"
name="email"
required
aria-required="true"
aria-describedby="email-desc"
/>
<p id="email-desc" class="sr-only">Provide a valid email address</p>
</div>
<br />
<div>
<label for="password">Password:</label>
<input
type="password"
id="password"
name="password"
required
aria-required="true"
aria-describedby="password-desc"
/>
<p id="password-desc" class="sr-only">Choose a secure password</p>
</div>
<br />
<fieldset>
<legend>Gender:</legend>
<label>
<input
type="radio"
name="gender"
value="male"
required
aria-required="true"
/>Male
</label>
<label>
<input type="radio" name="gender" value="female" />Female
</label>
<label>
<input type="radio" name="gender" value="other" />Other
</label>
</fieldset>
<br />
<div>
<label for="dob">Date of Birth:</label>
<input
type="date"
id="dob"
name="dob"
required
aria-required="true"
aria-describedby="dob-desc"
/>
<p id="dob-desc" class="sr-only">Select your birth date</p>
</div>
<br />
<div>
<label class="labelWide">
<input
type="checkbox"
name="terms"
required
aria-required="true"
/>
I agree to the Terms and Conditions
</label>
</div>
<br />
<button type="submit" aria-label="Register for the site">
Register
</button>
</form>
</main>
</div>
<!-- MODAL -->
<div
id="modal"
role="dialog"
aria-labelledby="modal_mesg"
aria-hidden="true"
>
<div id="modalContent">
<p id="modal_mesg">Form submitted successfully!</p>
<button id="closeModal" aria-label="Close this modal">Close</button>
</div>
</div>
<script>
const form = document.getElementById("exer02form");
const modal = document.getElementById("modal");
const closeModalButton = document.getElementById("closeModal");
form.addEventListener("submit", function (event) {
event.preventDefault();
// SIMPLE VALIDATION
let mesg_str = "Form data is valid!";
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const password = document.getElementById("password").value.trim();
const gender = document.querySelector("input[name='gender']:checked");
const dob = document.getElementById("dob").value.trim();
const terms = document.querySelector("input[name='terms']").checked;
let errors = [];
if (name.length <= 2) {
errors.push("Full Name must be longer than 2 characters.");
}
if (!email) {
errors.push("Email Address is required.");
}
if (!password || password.length < 5) {
errors.push("Password longer than 5 characters is required.");
}
if (!gender) {
errors.push("Please select a Gender.");
}
if (!dob) {
errors.push("Date of Birth is required.");
}
if (!terms) {
errors.push("You must agree to the Terms and Conditions.");
}
if (errors.length > 0) {
// alert(errors.join("\n"));
mesg_str = errors.join("\n");
}
// SET THE MESG ON THE MODAL
document.querySelector("#modal_mesg").innerHTML = mesg_str;
// DISPLAY THE MODAL
modal.style.display = "flex";
modal.setAttribute("aria-hidden", "false");
});
closeModalButton.addEventListener("click", function () {
modal.style.display = "none";
modal.setAttribute("aria-hidden", "true");
});
</script>
</body>
</html>