-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
41 lines (37 loc) · 1.03 KB
/
javascript.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
window.addEventListener("load",function() {
const form = document.getElementById("songform");
form.addEventListener('submit',function(e) {
let result = validate();
if (result === true) {
e.preventDefault();
let errorDiv = document.getElementById("errorDiv");
errorDiv.innerHTML = "Error, please check title and artist are both filled.";
}
if (result === false) {
e.preventDefault();
let successDiv = document.getElementById("successDiv");
successDiv.innerHTML = "Song added successfully.";
} else {
return true;
}
});
function validate() {
titleSelection = false;
const email = document.getElementById("title");
if (email.value.length > 0) {
titleSelection = true;
}
artistSelection = false;
const year = document.getElementById("artist");
if (year.value.length > 0) {
artistSelection = true;
}
if (titleSelection === false || artistSelection === false) {
console.log("Something is not selected");
return true;
} else {
console.log("Form is valid");
return false;
}
};
});