-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (33 loc) · 1.4 KB
/
script.js
File metadata and controls
39 lines (33 loc) · 1.4 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
document.addEventListener("DOMContentLoaded", function () {
const roundTripCheckbox = document.getElementById("roundTrip");
const returnDateGroup = document.getElementById("returnDateGroup");
roundTripCheckbox.addEventListener("change", function () {
if (this.checked) {
returnDateGroup.style.display = "block";
document.getElementById("returnDate").setAttribute("required", "required");
} else {
returnDateGroup.style.display = "none";
document.getElementById("returnDate").removeAttribute("required");
}
});
function validateEmail(email) {
const re = /\S+@\S+\.\S+/;
return re.test(email);
}
document.getElementById("ticketForm").addEventListener("submit", function (event) {
const emailInput = document.getElementById("email");
const emailError = document.getElementById("emailError");
if (!validateEmail(emailInput.value)) {
event.preventDefault();
emailError.style.display = "block";
return false;
} else {
emailError.style.display = "none";
}
});
const emailInput = document.getElementById("email");
const emailError = document.getElementById("emailError");
emailInput.addEventListener("input", function () {
emailError.style.display = "none";
});
});