Repository navigation
Expand file tree
/
Copy pathform_inline.html
More file actions
423 lines (356 loc) · 13.3 KB
/
Copy pathform_inline.html
File metadata and controls
423 lines (356 loc) · 13.3 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form A - Inline Validation</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
max-width: 540px;
width: 100%;
padding: 48px;
border-radius: 24px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
h1 {
color: #1a202c;
font-size: 32px;
font-weight: 700;
margin-bottom: 8px;
text-align: center;
}
.subtitle {
color: #718096;
font-size: 16px;
margin-bottom: 36px;
text-align: center;
font-weight: 500;
}
.form-group {
margin-bottom: 24px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #2d3748;
font-size: 14px;
letter-spacing: 0.3px;
}
input,
select {
width: 100%;
padding: 14px 16px;
border: 2px solid #e2e8f0;
border-radius: 12px;
font-size: 15px;
font-family: inherit;
transition: all 0.3s ease;
background: #f7fafc;
}
input:focus,
select:focus {
outline: none;
border-color: #667eea;
background: white;
box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}
input.error {
border-color: #fc8181;
background: #fff5f5;
}
.error-message {
color: #e53e3e;
font-size: 13px;
margin-top: 6px;
display: none;
font-weight: 500;
}
.error-message.show {
display: block;
animation: slideDown 0.3s ease;
}
@keyframes slideDown {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 16px 32px;
border: none;
border-radius: 12px;
cursor: pointer;
font-size: 16px;
font-weight: 600;
width: 100%;
margin-top: 12px;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}
button:active {
transform: translateY(0);
}
.results {
display: none;
}
.results.show {
display: block;
animation: fadeIn 0.5s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.result-item {
background: linear-gradient(135deg, #f6f8fb 0%, #e9ecf5 100%);
padding: 24px;
margin: 16px 0;
border-radius: 16px;
border-left: 5px solid #667eea;
transition: transform 0.3s ease;
}
.result-item:hover {
transform: translateX(5px);
}
.result-label {
font-weight: 600;
color: #4a5568;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 8px;
}
.result-value {
font-size: 36px;
font-weight: 700;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
</style>
</head>
<body>
<div class="container">
<div id="formSection">
<h1>User Registration Form</h1>
<p class="subtitle">Version A: Inline Validation</p>
<form id="userForm">
<div class="form-group">
<label for="fullName">Full Name *</label>
<input type="text" id="fullName" name="fullName" required>
<div class="error-message" id="fullNameError">Please enter your full name (at least 2 words)</div>
</div>
<div class="form-group">
<label for="email">Email Address *</label>
<input type="email" id="email" name="email" required>
<div class="error-message" id="emailError">Please enter a valid email address</div>
</div>
<div class="form-group">
<label for="phone">Phone Number *</label>
<input type="tel" id="phone" name="phone" required>
<div class="error-message" id="phoneError">Please enter a valid 10-digit phone number</div>
</div>
<div class="form-group">
<label for="age">Age *</label>
<input type="number" id="age" name="age" required>
<div class="error-message" id="ageError">Age must be between 18 and 120</div>
</div>
<div class="form-group">
<label for="country">Country *</label>
<select id="country" name="country" required>
<option value="">Select a country</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
<option value="UK">United Kingdom</option>
<option value="AU">Australia</option>
<option value="DE">Germany</option>
<option value="FR">France</option>
<option value="JP">Japan</option>
<option value="IN">India</option>
<option value="BR">Brazil</option>
<option value="MX">Mexico</option>
</select>
<div class="error-message" id="countryError">Please select a country</div>
</div>
<button type="submit">Submit</button>
</form>
</div>
<div id="resultsSection" class="results">
<h1>Submission Successful!</h1>
<p class="subtitle">Thank you for completing the form</p>
<div class="result-item">
<div class="result-label">Completion Time</div>
<div class="result-value" id="completionTime">0</div>
</div>
<div class="result-item">
<div class="result-label">Number of Error Messages</div>
<div class="result-value" id="errorCount">0</div>
</div>
<div class="result-item">
<div class="result-label">Submission Attempts</div>
<div class="result-value" id="attemptCount">0</div>
</div>
</div>
</div>
<script>
let startTime = Date.now();
let errorCount = 0;
let attemptCount = 0;
const form = document.getElementById('userForm');
const inputs = {
fullName: document.getElementById('fullName'),
email: document.getElementById('email'),
phone: document.getElementById('phone'),
age: document.getElementById('age'),
country: document.getElementById('country')
};
function validateFullName(value) {
const words = value.trim().split(/\s+/);
return words.length >= 2 && words.every(w => w.length > 0);
}
function validateEmail(value) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
}
function validatePhone(value) {
const digits = value.replace(/\D/g, '');
return digits.length === 10;
}
function validateAge(value) {
const age = parseInt(value);
return !isNaN(age) && age >= 18 && age <= 120;
}
function validateCountry(value) {
return value !== '';
}
function showError(fieldId, show) {
const input = inputs[fieldId];
const errorDiv = document.getElementById(fieldId + 'Error');
if (show) {
input.classList.add('error');
errorDiv.classList.add('show');
errorCount++;
} else {
input.classList.remove('error');
errorDiv.classList.remove('show');
}
}
// Inline validation on blur
inputs.fullName.addEventListener('blur', function () {
if (this.value && !validateFullName(this.value)) {
showError('fullName', true);
}
});
inputs.fullName.addEventListener('input', function () {
if (this.classList.contains('error') && validateFullName(this.value)) {
showError('fullName', false);
}
});
inputs.email.addEventListener('blur', function () {
if (this.value && !validateEmail(this.value)) {
showError('email', true);
}
});
inputs.email.addEventListener('input', function () {
if (this.classList.contains('error') && validateEmail(this.value)) {
showError('email', false);
}
});
inputs.phone.addEventListener('blur', function () {
if (this.value && !validatePhone(this.value)) {
showError('phone', true);
}
});
inputs.phone.addEventListener('input', function () {
if (this.classList.contains('error') && validatePhone(this.value)) {
showError('phone', false);
}
});
inputs.age.addEventListener('blur', function () {
if (this.value && !validateAge(this.value)) {
showError('age', true);
}
});
inputs.age.addEventListener('input', function () {
if (this.classList.contains('error') && validateAge(this.value)) {
showError('age', false);
}
});
inputs.country.addEventListener('change', function () {
if (this.value) {
showError('country', false);
}
});
form.addEventListener('submit', function (e) {
e.preventDefault();
attemptCount++;
let isValid = true;
// Clear previous errors for validation
Object.keys(inputs).forEach(key => {
inputs[key].classList.remove('error');
document.getElementById(key + 'Error').classList.remove('show');
});
// Validate all fields
if (!validateFullName(inputs.fullName.value)) {
showError('fullName', true);
isValid = false;
}
if (!validateEmail(inputs.email.value)) {
showError('email', true);
isValid = false;
}
if (!validatePhone(inputs.phone.value)) {
showError('phone', true);
isValid = false;
}
if (!validateAge(inputs.age.value)) {
showError('age', true);
isValid = false;
}
if (!validateCountry(inputs.country.value)) {
showError('country', true);
isValid = false;
}
if (isValid) {
const completionTime = ((Date.now() - startTime) / 1000).toFixed(2);
document.getElementById('completionTime').textContent = completionTime + ' seconds';
document.getElementById('errorCount').textContent = errorCount;
document.getElementById('attemptCount').textContent = attemptCount;
document.getElementById('formSection').style.display = 'none';
document.getElementById('resultsSection').classList.add('show');
}
});
</script>
</body>
</html>