-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
120 lines (93 loc) · 3.69 KB
/
Copy pathscript.js
File metadata and controls
120 lines (93 loc) · 3.69 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
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
113
114
115
116
117
118
119
120
document.querySelector('.Contact-form').addEventListener('submit', function(event){
let isValid = true;
const firstName = document.querySelector('#first-name')
const errorMessage = document.querySelector('#error-message')
const lastName = document.querySelector('#last-name')
const errormessage2 = document.querySelector('#error-message2')
const TextAreaError = document.querySelector('#TextAreaError')
const textArea = document.querySelector('#textArea')
let SuccessMessage = document.querySelector('.success')
if (firstName.value.trim() === ""){
event.preventDefault();
errorMessage.innerText = "This feild is required"
errorMessage.style.display = "block"
firstName.style.borderColor = "red"
isValid = false;
}else{
errorMessage.style.display = "none"
firstName.style.borderColor = ""
}
if (lastName.value.trim() === ""){
event.preventDefault();
errormessage2.innerText = "This feild is required"
errormessage2.style.display = "block"
lastName.style.borderColor="red"
isValid = false;
}else{
errormessage2.style.display = "none"
lastName.style.borderColor=""
}
if (textArea.value.trim()===""){
event.preventDefault();
TextAreaError.innerText = "This field is required"
TextAreaError.style.display = "block"
textArea.style.borderColor="red"
isValid = false;
}else{
TextAreaError.style.display = "none"
textArea.style.borderColor=""
}
const emailError = document.querySelector('#emailError')
const Email = document.querySelector('#Email')
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(Email.value.trim())){
event.preventDefault();
emailError.innerText="please enter a valid email address"
emailError.style.display ="block"
Email.style.borderColor = "red"
isValid = false;
}else{
emailError.style.display ="none"
Email.style.borderColor = ""
}
const radios = document.getElementsByName('radio');
const radioErorMessage = document.getElementById('radio-error-message');
let isRadioSelected = false;
radios.forEach(function(radio) {
if (radio.checked) {
isRadioSelected = true; // A radio button is selected
}
});
if (!isRadioSelected) {
event.preventDefault(); // Prevent form submission
radioErorMessage.innerText = "Please select a query type";
radioErorMessage.style.display = "block"; // Show the error
isValid = false;
} else {
radioErorMessage.style.display = "none"; // Hide the error message if a radio is selected
}
const checkmark = document.querySelector('#checkbox')
const checkboxErrorMessage = document.querySelector('#checkbox-error-message')
if(!checkmark.checked){
event.preventDefault();
checkboxErrorMessage.innerText = "To submit this form, please consent to being contacted"
checkboxErrorMessage.style.display = "block"
isValid = false;
}else{
checkboxErrorMessage.style.display = "none"
}
if (isValid) {
// SuccessMessage.classList.add('visible');
SuccessMessage.style.display="flex";
setTimeout(function(){
document.querySelector('.Contact-form').reset();
window.location.reload();
},5000)
// alert("Form submitted successfully!");
// Reset the form fields
}
})
// let prove = document.querySelector('.prove')
// prove.addEventListener('click', function(){
// prove.style.display = "none"
// })