-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (33 loc) · 1.03 KB
/
app.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
"use strict;"
let lastBookId = 0;
function loaded() {
console.log("Page has loaded");
let formEl = document.getElementById('formEl');
formEl.addEventListener('submit', onBookAdd, false)
}
function onBookAdd(event) {
event.preventDefault();
console.log("Add book")
let bookListBody = document.getElementById('bookListBody');
row = `
<tr id="bookRow${lastBookId}">
<td>${lastBookId + 1}</td>
<td>${event.target.bookTitle.value}</td>
<td>${event.target.bookGenre.value}</td>
<td>${event.target.bookDesc.value}</td>
<td>
<button>Edit</button>
<button onclick="onBookDelete(${lastBookId})">Delete</button>
</td>
</tr>
`
bookListBody.insertAdjacentHTML("beforeend", row);
lastBookId++;
}
function onBookDelete(bookId) {
console.log("Delete book")
let bookListBody = document.getElementById('bookListBody');
let bookRow = document.getElementById('bookRow'+bookId);
bookListBody.removeChild(bookRow);
}
document.addEventListener("DOMContentLoaded", loaded);