-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaq.js
More file actions
75 lines (62 loc) · 1.81 KB
/
faq.js
File metadata and controls
75 lines (62 loc) · 1.81 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
//drop-down
const items = document.querySelectorAll(".faq button");
function togglefaq() {
const itemToggle = this.getAttribute("aria-expanded");
for (i = 0; i < items.length; i++) {
items[i].setAttribute("aria-expanded", "false");
}
if (itemToggle == "false") {
this.setAttribute("aria-expanded", "true");
}
}
//form
items.forEach((item) => item.addEventListener("click", togglefaq));
const form = document.getElementById("form");
const username = document.getElementById("username");
const email = document.getElementById("email");
const feedback = document.getElementById("feedbacks");
// const password2 = document.getElementById("password2");
form.addEventListener("submit", (e) => {
e.preventDefault();
checkInputs();
});
function checkInputs() {
// trim to remove the whitespaces
const usernameValue = username.value.trim();
const emailValue = email.value.trim();
const feedbackValue = feedback.value.trim();
// const password2Value = password2.value.trim();
let c = 0;
if (usernameValue === "") {
setErrorFor(username, "Username cannot be blank");
} else {
setSuccessFor(username);
c++;
}
if (emailValue === "") {
setErrorFor(email, "Email cannot be blank");
} else {
setSuccessFor(email);
c++;
}
if (feedbackValue === "") {
setErrorFor(feedback, "Please enter some feedback");
} else {
setSuccessFor(feedback);
c++;
}
if (c == 3) {
alert("Thank you for your feedback !");
location.reload();
}
}
function setErrorFor(input, message) {
const formControl = input.parentElement;
const small = formControl.querySelector("small");
formControl.className = "form-control error";
small.innerText = message;
}
function setSuccessFor(input) {
const formControl = input.parentElement;
formControl.className = "form-control success";
}