I'm struggling with my form input not showing up under the table headings after submission. I've reviewed the code multiple times, but can't figure out what's causing the issue.
If you have any suggestions on how to write the code more efficiently and correctly, please share your insights.
After entering values and submitting, the table remains unchanged with no updates or modifications.
var form = document.getElementById("form");
var table = document.getElementById("table");
form.addEventListener("submit", addItem);
function addItem(e) {
e.preventDefault();
var customerName = document.getElementById("customerName").value;
var itemPurchased = document.getElementById("itemPurchased").value;
var quantity = document.getElementById("quantity").value;
var date = document.getElementById("date").value;
var row = table.insertRow(2);
var customerCell = row.insertCell(0);
customerCell.innerHTML = customerName;
var ItemCell = row.insertCell(1);
ItemCell.innerHTML = itemPurchased;
var quantityCell = row.insertCell(2);
quantityCell.innerHTML = quantity;
var dateCell = row.insertCell(3);
dateCell.innerHTML = date;
var DeleteCell = row.insertCell(4);
DeleteCell.innerHTML = x;
}
<div class="container">
<div class="Form-container">
<form id="form">
<label for="customerName" class="input-title">CUSTOMER NAME</label><br>
<input type="text" class="record-input" id="customerName" required><br><br><br>
<label for="itemPurchased" class="input-title">ITEM PURCHASED</label><br>
<input type="text" class="record-input" id="itemPurchased" required><br><br><br>
<label for="quantity" class="input-title">QUANTITY</label><br>
<input type="text" class="record-input" id="quantity" required><br><br><br>
<label for="date" class="input-title">Date</label><br>
<input type="date" class="record-input" id="DATE" required><br><br>
<input type="submit" value="Submit" class="record-submit">
</form>
</div>
<div class="record-container" id="container">
<table id="table">
<tr>
<th>CUSTOMER NAME</th>
<th>ITEM PURCHASED</th>
<th>QUANTITY</th>
<th>DATE</th>
</tr>
<tr>
<td>EBUBE ODINAKA</td>
<td>iPhone 11 pro max</td>
<td>1</td>
<td>07/01/2021</td>
<td class="deleteTable"><button>x</button></td>
</tr>
</table>
</div>
</div>