-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (35 loc) · 1.53 KB
/
script.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
42
43
document.addEventListener('DOMContentLoaded', function () {
const productForm = document.getElementById('productForm');
const inventoryTableBody = document.querySelector('#inventoryTable tbody');
productForm.addEventListener('submit', function (e) {
e.preventDefault();
const productName = document.getElementById('productName').value;
const productQuantity = document.getElementById('productQuantity').value;
const productPrice = document.getElementById('productPrice').value;
// Example of adding a product (this would be where you'd send data to the server)
const productData = {
name: productName,
quantity: productQuantity,
price: productPrice
};
// You'd likely send this data to a server via fetch/AJAX
// Simulate adding product to the table
addProductToTable(productData);
// Reset the form
productForm.reset();
});
function addProductToTable(product) {
const row = document.createElement('tr');
row.innerHTML = `
<td>${Math.floor(Math.random() * 10000)}</td>
<td>${product.name}</td>
<td>${product.quantity}</td>
<td>${product.price}</td>
<td><button class="delete-btn">Delete</button></td>
`;
inventoryTableBody.appendChild(row);
row.querySelector('.delete-btn').addEventListener('click', function () {
row.remove();
});
}
});