-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (22 loc) · 835 Bytes
/
Copy pathscript.js
File metadata and controls
24 lines (22 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const expenseForm = document.getElementById("expensedetails");
const expenselist = document.getElementById("expenselist");
const totalElement = document.getElementById("total");
let total = 0;
expenseForm.addEventListener("submit", function(event) {
event.preventDefault();
const description = document.getElementById("description").value;
const category = document.getElementById("category").value;
const amount = parseFloat(document.getElementById("amount").value);
if (description && category && !isNaN(amount)) {
const newRow = document.createElement("tr");
newRow.innerHTML = `
<td>${description}</td>
<td>${category}</td>
<td>${amount}</td>
`;
expenselist.appendChild(newRow);
total += amount;
totalElement.textContent = `Total: ${total}`;
expenseForm.reset();
}
});