From b417121f90a07385666158253f50ba95f317da56 Mon Sep 17 00:00:00 2001 From: Hadi Vahidi Date: Sun, 14 Dec 2025 22:16:03 +0000 Subject: [PATCH 1/3] Fix book submission logic and improve event handling in the library app --- debugging/book-library/index.html | 2 +- debugging/book-library/script.js | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..717d76cd 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -65,7 +65,7 @@

Library

type="submit" value="Submit" class="btn btn-primary" - onclick="submit();" + onclick="submitBook();" /> diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..52ef99c4 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -1,6 +1,6 @@ let myLibrary = []; -window.addEventListener("load", function (e) { +window.addEventListener("load", function () { populateStorage(); render(); }); @@ -27,19 +27,25 @@ const check = document.getElementById("check"); //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function -function submit() { +function submitBook() { if ( title.value == null || title.value == "" || + author.value == null || + author.value == "" || pages.value == null || pages.value == "" ) { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + let book = new Book(title.value, author.value, pages.value, check.checked); + myLibrary.push(book); render(); + title.value = ""; + author.value = ""; + pages.value = ""; + check.checked = false; } } @@ -54,7 +60,7 @@ function render() { let table = document.getElementById("display"); let rowsNumber = table.rows.length; //delete old table - for (let n = rowsNumber - 1; n > 0; n-- { + for (let n = rowsNumber - 1; n > 0; n--) { table.deleteRow(n); } //insert updated row and cells @@ -76,7 +82,7 @@ function render() { changeBut.className = "btn btn-success"; wasReadCell.appendChild(changeBut); let readStatus = ""; - if (myLibrary[i].check == false) { + if (myLibrary[i].check == true) { readStatus = "Yes"; } else { readStatus = "No"; @@ -90,11 +96,11 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); - delBut.id = i + 5; - deleteCell.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delButton.id = i + 5; + deleteCell.appendChild(delButton); + delButton.className = "btn btn-warning"; + delButton.innerHTML = "Delete"; + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 1c7e946b7a9f0127701503778a41f7e57d5f89f7 Mon Sep 17 00:00:00 2001 From: Hadi Vahidi Date: Sat, 20 Dec 2025 13:21:47 +0000 Subject: [PATCH 2/3] Fix HTML validation errors --- debugging/book-library/index.html | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 717d76cd..0cd83ecc 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -1,20 +1,17 @@ - + - - + Library + + - + > + @@ -31,20 +28,20 @@

Library

+ > + > Library id="pages" name="pages" required - /> + > + >
From 3233ca61f36d6f41c5769a44c72f8db62fa212f5 Mon Sep 17 00:00:00 2001 From: Hadi Vahidi Date: Sat, 20 Dec 2025 20:56:12 +0000 Subject: [PATCH 3/3] Enhance book submission logic and input validation in the library app --- debugging/book-library/index.html | 6 +- debugging/book-library/script.js | 115 ++++++++++++++---------------- 2 files changed, 59 insertions(+), 62 deletions(-) diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 0cd83ecc..1e3a2e69 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -48,6 +48,8 @@

Library

class="form-control" id="pages" name="pages" + min="1" + step="1" required >