-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.js
114 lines (91 loc) · 2.78 KB
/
signup.js
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
let username = document.getElementById("name");
let course = document.getElementById("course");
let email = document.getElementById("email");
let password = document.getElementById("pass");
let confirmPassword = document.getElementById("ConPass");
let signUpFrom = document.getElementById("signUpForm");
let signUpDiv = document.getElementById("signUpDiv");
let formDisplay = document.getElementById("formDisplay");
let closeForm = document.getElementById("closeForm");
let button = document.getElementById("signUpButton");
/**
* adding keyup function to buttons.
*/
const inputFields = document.getElementsByClassName("inputvalitation");
for (let i = 0; i < inputFields.length; i++) {
const el = inputFields[i];
el.addEventListener("keypress", (e) => {
el.style.boxShadow = "0px 0px 6px 1px green";
});
}
/**
* adding keydown function to buttons.
*/
let inputBox = document.getElementsByClassName("inputvalitation");
for (let i = 0; i < inputBox.length; i++) {
const el = inputBox[i];
el.addEventListener("keydown", (e) => {
el.style.boxShadow = "none";
});
}
/**
* displaying form on click.
*/
function displayForm() {
signUpDiv.style.visibility = "visible";
loginDiv.style.visibility = "hidden";
}
formDisplay.addEventListener("click", displayForm);
/**
* form validation function
*/
function signSubmit(event) {
if (username.value == "") {
username.style.boxShadow = "0px 0px 6px 1px red";
return false;
} else {
username.style.boxShadow = "0px 0px 6px 1px green";
}
if (course.value == "") {
course.style.boxShadow = "0px 0px 6px 1px red";
return false;
} else {
course.style.boxShadow = "0px 0px 6px 1px green";
}
if (email.value == "") {
email.style.boxShadow = "0px 0px 6px 1px red";
return false;
} else {
email.style.boxShadow = "0px 0px 6px 1px green";
}
if (password.value == "") {
password.style.boxShadow = "0px 0px 6px 1px red";
return false;
} else {
password.style.boxShadow = "0px 0px 6px 1px green";
}
if (confirmPassword.value == "") {
confirmPassword.style.boxShadow = "0px 0px 6px 1px red";
return false;
} else {
confirmPassword.style.boxShadow = "0px 0px 6px 1px green";
}
if (password.value != confirmPassword.value) {
event.preventDefault();
password.style.boxShadow = "0px 0px 6px 1px red";
confirmPassword.style.boxShadow = "0px 0px 6px 1px red";
alert("confirm Password and password must be same");
return false;
} else {
password.style.boxShadow = "0px 0px 6px 1px green";
confirmPassword.style.boxShadow = "0px 0px 6px 1px green";
}
}
button.addEventListener("click", signSubmit);
/**
* Hide the sign form on click.
*/
function hideForm() {
signUpDiv.style.visibility = "hidden";
}
closeForm.addEventListener("click", hideForm);