-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
42 lines (31 loc) · 1.04 KB
/
script.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
let id = (id) => document.getElementById(id);
let classes = (classes) => document.getElementsByClassName(classes);
let fname = id("fname"),
lname = id("lname"),
email = id("email"),
password = id("pword"),
form = id("form"),
errorMsg = classes("error"),
failureIcon = classes("failure-icon");
// Adding the submit event Listener
form.addEventListener("submit", (e) => {
e.preventDefault();
engine(fname, 0, "First name can not be empty");
engine(lname, 1, "Last name can not be empty");
engine(email, 2, "Looks like this is not an email");
engine(password, 3, "Password can not be empty");
});
// engine function which will do all the works
let engine = (id, serial, message) => {
if (id.value.trim() === "") {
errorMsg[serial].innerHTML = message;
id.style.border = "2px solid red";
// icons
failureIcon[serial].style.opacity = "1";
} else {
errorMsg[serial].innerHTML = "";
id.style.border = "2px solid green";
// icons
failureIcon[serial].style.opacity = "0";
}
};