-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbyvalid.js
More file actions
30 lines (28 loc) · 835 Bytes
/
byvalid.js
File metadata and controls
30 lines (28 loc) · 835 Bytes
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
function validateForm() {
var quantity = document.getElementById("quantity").value;
var sizes = document.getElementsByName("size[]");
var option = document.querySelector('input[name="option"]:checked');
var errorMessage = '';
if (quantity === "") {
errorMessage += "Please select a quantity.\n";
}
var sizeSelected = false;
for (var i = 0; i < sizes.length; i++) {
if (sizes[i].checked) {
sizeSelected = true;
break;
}
}
if (!sizeSelected) {
errorMessage += "Please select at least one size.\n";
}
if (!option) {
errorMessage += "Please select an option (Egg).\n";
}
if (errorMessage !== '') {
alert(errorMessage);
return false;
}
window.location.href = "Buy-Now.php";
return false;
}