-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
73 lines (62 loc) · 1.72 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
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
// ACIP Internship Task 1
// Author: Zaryab Hussain
// JavaScript File
var onclick = false;
var isVisible = true;
function submitForm() {
var form = document.getElementById("registrationForm");
var formData = new FormData(form);
var output = document.getElementById("formData");
var input = document.querySelectorAll(".input");
var container = document.getElementById("container");
input.forEach((item) => {
console.log(item.value);
item.value = "";
});
// Clear previous output
output.innerHTML = "";
// Check for empty fields
let hasEmptyField = false;
formData.forEach((value) => {
if (value == "") {
hasEmptyField = true;
}
});
// If there's any empty field, return early
if (hasEmptyField) {
alert("Please fill in all fields.");
return;
}
window.scrollTo(0, 0);
// Toggle onclick state
onclick = !onclick;
if (!onclick) {
container.style.display = "none";
}
// Display the form data
output.style.display = "block";
output.innerHTML = "<h3>Form Data</h3>";
formData.forEach(function (value, key) {
output.innerHTML += "<p><strong>" + key + ":</strong> " + value + "</p>";
});
const para = document.createElement("div");
para.innerHTML = "⤬";
para.classList.add("cross");
para.id = "cross";
// Prepend the newly created element to the output div
output.prepend(para);
var cross = document.getElementById("cross");
cross.addEventListener("click", (e) => {
console.log("clicked");
isVisible = !isVisible;
if (isVisible) {
output.style.display = "block";
} else {
output.style.display = "none";
container.style.display = "block";
formData.forEach((item) => {
item = "";
});
}
});
}