-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptv2.js
More file actions
41 lines (34 loc) · 1.16 KB
/
scriptv2.js
File metadata and controls
41 lines (34 loc) · 1.16 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
function extractDataFromForm(event) {
event.preventDefault();
// Get the values from the input fields
const titleValue = document.getElementById("book-title").value;
const authorValue = document.getElementById("author").value;
const pagesValue = document.getElementById("pages").value;
const ratingValue = document.getElementById("rating").value;
const coverFiles = document.getElementById("upload");
const bookCover = coverFiles.files[0];
if (checkDuplicate(titleValue, authorValue)) {
alert("Duplicate!");
const title = document.getElementById("book-title");
const errorMessage = document.createElement("p");
errorMessage.textContent = "Duplicate found! Check the library";
errorMessage.classList.add("invalid-message");
title.insertAdjacentElement(`afterend`, errorMessage);
return;
}
// Retrieves data from dropdown selection
const status = document.querySelector('select[name="status"]').value;
const startingBook = false;
bookList.push(
new Book(
titleValue,
authorValue,
pagesValue,
ratingValue,
status,
startingBook,
bookCover
)
);
addBookToTheContainer();
}