function getBookData(isbn) { var table = document.getElementById("books-table"); // Find all rows in the table except the header var rows = table.getElementsByTagName("tr"); // Iterate through each row for (var i = 1; i < rows.length; i++) { // starting from 1 to skip the header row var cells = rows[i].getElementsByTagName("td"); // Check if the ISBN in the current row matches the given ISBN if (cells[0].innerText == isbn) { // Extract data from the row var title = cells[1].innerText; var author = cells[2].innerText; var date = cells[3].innerText; var publisher = cells[4].innerText; var category = cells[5].innerText; var quantity = cells[6].innerText; // Return the data return { title: title, author: author, date: date, publisher: publisher, category: category, quantity: quantity }; } } // If ISBN is not found, return null return null; } function openEditBookDialog(isbn) { var bookData = getBookData(isbn); if (bookData) { var editDialog = document.getElementById("edit-book-dialog"); document.getElementById("edit-isbn").value = isbn; document.getElementById("edit-title").value = bookData.title; document.getElementById("edit-author").value = bookData.author; document.getElementById("edit-date").value = bookData.date; document.getElementById("edit-publisher").value = bookData.publisher; document.getElementById("edit-category").value = bookData.category; document.getElementById("edit-quantity").value = bookData.quantity; editDialog.showModal(); } else { alert("Book not found!"); } } // Function to hide the edit-book dialog function hideEditBookDialog() { var editDialog = document.getElementById("edit-book-dialog"); editDialog.close(); } // Function to show the delete-book dialog function openDeleteBookDialog(isbn) { var bookData = getBookData(isbn); console.log(isbn, bookData) if (bookData === null) return; var deleteDialog = document.getElementById("delete-book-dialog"); document.getElementById("delete-isbn").value = isbn; document.getElementById("delete-book-name").innerText = bookData.title; if (bookData.title === undefined || bookData.title == "None") document.getElementById("delete-book-name").innerText = "ISBN:"+isbn; deleteDialog.showModal(); // Handle cancel delete document.getElementById("cancel-delete").onclick = function() { deleteDialog.close(); }; } // Function to hide the delete-book dialog function hideDeleteBookDialog() { var deleteDialog = document.getElementById("delete-book-dialog"); deleteDialog.close(); }