I'm still trying to find a way to get the addToCart() function to work.
fetch('server.php')
.then((res) => res.json())
.then((response) => {
let output = '';
for (let i in response) {
output += `<tr>
<td>${response[i].quantity}</td>
<td><button>${response[i].productName}</button></td>
<td>₦${response[i].price}.00</td>
<td><button id="go" onclick="addToCart()">+1</button></td>
<td><input type="text"></td>
</tr>`;
}
document.querySelector('.tbody').innerHTML = output;
})
.catch((error) => console.log(error));
function addToCart() {
document.getElementById('fillUp').innerHTML += '<tr><td>123</d></tr>';
console.log(val);
}
<!-- Product Table -->
<table id="myTable">
<thead class="tHeadRow">
<th>Quantity</th>
<th>Products</th>
<th>Price</th>
</thead>
<tbody class="tbody"></tbody>
</table>
<!-- Cart Table -->
<div class="cart">
<h3>Checkout Cart</h3>
<div class="cartContent">
<table class="cartTable">
<tbody id="fillUp"></tbody>
<tfoot>
<tr>
<td style="font-weight: bold">Total:</td>
<td style="font-weight: bold"></td>
</tr>
</tfoot>
</table>
</div>
</div>
<!--- I got a possible solution but when I tried it, I got Uncaught --->
<!--- TypeError: Cannot read properties of null (reading 'rows') --->
var tbody = document.getElementById('tbody'),rIndex;
var tb = tbody.rows.length;
for(var i = 0; i < tb; i++) {
tbody.rows[i].onclick = function() {
console.log(this.cells[0].innerHTML);
}