-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (62 loc) · 1.75 KB
/
script.js
File metadata and controls
74 lines (62 loc) · 1.75 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
const form = document.getElementById('form');
const password1 = document.getElementById('password1');
const password2 = document.getElementById('password2');
const messageContainer = document.querySelector('message-container');
const message = document.getElementById('message');
let isValid = false;
let passwordsMatch = false;
function validateForm()
{
//using Constraint validation API
isValid = form.checkValidity();
if(!isValid)
{
message.textContent = 'Please fill out all fields.';
message.style.color = 'red';
message.style.borderColor ='red';
return;
}
if(password1.value === password2.value)
{
passwordsMatch = true;
password1.style.borderColor ='green';
password2.style.borderColor ='green';
}
else
{
passwordsMatch = false;
password1.style.color = 'red';
password2.style.color = 'red';
password1.style.borderColor ='red';
password2.style.borderColor ='red';
message.textContent = 'Passwords must match.';
message.style.color = 'red';
message.style.borderColor ='red';
return;
}
if(isValid && passwordsMatch)
{
message.textContent = 'Suuccessfully Rgistered!';
message.style.color = 'green';
message.style.borderColor ='green';
storeFormData()
}
}
function storeFormData()
{
const user = {
name: form.username.value,
email: form.email.value,
phone: form.phone.value,
website: form.website.value,
password: form.password.value
}
console.log(user);
alert(JSON.stringify(user));
}
function formData(e)
{
e.preventDefault();
validateForm();
}
form.addEventListener('submit', formData)