-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.js
63 lines (50 loc) · 1.77 KB
/
forms.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
// this section is for the find a dog part
const dogForm = document.getElementById("find-dog-form");
dogForm.addEventListener('submit', (event) => {
const elements = dogForm.elements;
let checkboxChecked = false;
let radioChecked = false;
// Loop through all elements in the form
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
// check if the element is a checkbox
if (element.type === "checkbox") {
if (element.checked) {
checkboxChecked = true;
}
}
if (element.type === "radio" && element.checked){
radioChecked = true;
}
// no need to check for select bc there no way there wont be a value
}
if (!checkboxChecked || !radioChecked) {
alert("Please fill out all of the fields");
event.preventDefault();
}
});
// for cat part
const catForm = document.getElementById("find-cat-form");
catForm.addEventListener('submit', (event) => {
const elements = catForm.elements;
let checkboxChecked = false;
let radioChecked = false;
// Loop through all elements in the form
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
// check if the element is a checkbox
if (element.type === "checkbox") {
if (element.checked) {
checkboxChecked = true;
}
}
if (element.type === "radio" && element.checked){
radioChecked = true;
}
// no need to check for select bc there no way there wont be a value
}
if (!checkboxChecked || !radioChecked) {
alert("Please fill out all of the fields");
event.preventDefault();
}
});