I have two problems with my vanilla JS exercise. I looked around the web and tried different code for two days now, and i'm honestly at a loss.
First, i have the checkbox input, where the user checks/unchecks a field. What i want is to have it written "yes" or "no" in a specific row field on webpage. The row gets created, but no matter what i try, it always writes "true/false" instead of what i want.
Input:
<label id="readlabel" for="read">Have you consumed the knowledge inside?</label><br>
<input type="checkbox" id="read" name="read">
checkbox gets created and appended to the table (id=myForm, table, tbody) solely with JS.
let book = {
...
read:document.getElementById("read").checked,
}
books.map((book) => {
...
let td5 = document.createElement("td");
td5.classList.add("checkTd");
td5.innerHTML = book.read;
row.appendChild(td5);
tbody.appendChild(row);
}
and the whole thing gets saved to local storage:
var existingBooks = JSON.parse(localStorage.getItem("BookList"));
if(existingBooks == null) existingBooks = [];
existingBooks.push(book);
localStorage.setItem("BookList", JSON.stringify(existingBooks));
books.splice(0,1);
Next up, there is the problem of deleting table rows. Button gets created and appended with JS:
books.map((book) => {
...
var td6 = document.createElement("button");
td6.innerHTML = "Delete";
td6.classList.add("deleteBtn");
row.appendChild(td6);
tbody.appendChild(row);
}
This button should delete the row of six cells on which the button is on. Again been trying different code for days with not a single one working. I hope the amount of code i pasted is enough.
Oh, and the code is organized as:
let books = []
const addBook =(ev)=> {
let book = {...}
books.push(book);
books.map((book) => {
"create and append"
})
save to storage
}
question from:
https://stackoverflow.com/questions/65641613/display-checkbox-input-as-text-in-a-row-created-with-js-and-delete-that-row 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…