-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform_validation.js
97 lines (82 loc) · 2.47 KB
/
form_validation.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
$(document).ready(function () {
$("#join_now_form").submit(function (event) {
event.preventDefault();
const name = $("#name").val();
const email = $("#email").val();
const password = $("#password").val();
const gender = $("input[name='radio']:checked").val();
const classes = $("#classes").val();
const checkbox = $("#checkbox").prop("checked");
// Validate the form
var valid = true;
if (!name) {
$("#name").addClass("invalid");
valid = false;
} else {
$("#name").removeClass("invalid");
}
if (!email) {
$("#email").addClass("invalid");
valid = false;
} else {
$("#email").removeClass("invalid");
}
if (!password) {
$("#password").addClass("invalid");
valid = false;
} else {
$("#password").removeClass("invalid");
}
if (!gender) {
$(".gender_field").addClass("invalid");
valid = false;
} else {
$(".gender_field").removeClass("invalid");
}
if (!classes) {
$(".classes_field").addClass("invalid");
valid = false;
} else {
$(".classes_field").removeClass("invalid");
}
if (!checkbox) {
$(".checkbox_container").addClass("invalid");
valid = false;
} else {
$(".checkbox_container").removeClass("invalid");
}
if (valid) {
const existingData = JSON.parse(localStorage.getItem("userData")) || [];
const newUserData = {
name: name,
email: email,
password: password,
gender: gender,
classes: classes,
};
existingData.push(newUserData);
localStorage.setItem("userData", JSON.stringify(existingData));
window.location.href = "../thank_you.html";
} else {
// alert("Please fill the all field!!");
const fail_con = $(".fail_container");
fail_con.addClass("show_fail");
setTimeout(function () {
fail_con.removeClass("show_fail");
}, 3000);
}
});
// Show and Hide Password Eye
$("#password_toggle").click(function () {
const passwordToggle = $("#password_toggle");
const passwordInput = $("#password");
const passwordFieldType = passwordInput.attr("type");
if (passwordFieldType === "password") {
passwordInput.attr("type", "text");
$(passwordToggle).removeClass("fa-eye-slash").addClass("fa-eye");
} else {
passwordInput.attr("type", "password");
$(passwordToggle).removeClass("fa-eye").addClass("fa-eye-slash");
}
});
});