-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (25 loc) · 1.07 KB
/
Copy pathindex.js
File metadata and controls
29 lines (25 loc) · 1.07 KB
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
let id = 0;
let createdDate = new Date();
document.getElementById('submit').addEventListener('click', () => {
let table = document.getElementById('list');
let row = table.insertRow(1); //position one = row 2
row.setAttribute('id', `item-${id}`);
row.insertCell(0).innerHTML = document.getElementById('new-bill').value;
row.insertCell(1).innerHTML = `${createdDate.getFullYear()}-${createdDate.getMonth() + 1}-${createdDate.getDate()}`;
row.insertCell(2).innerHTML = document.getElementById('date-due').value;
row.insertCell(3).innerHTML = document.getElementById('amount-due').value;
let actions = row.insertCell(4);
actions.appendChild(createPaidButton(id++));
document.getElementById('new-bill').value = '';
});
function createPaidButton(id) {
let btn = document.createElement('button');
btn.className = 'btn btn-success';
btn.id = id;
btn.innerHTML = 'Paid';
btn.onclick = () => {
let elementPaid = document.getElementById(`item-${id}`);
elementPaid.setAttribute("class", "table-success");
};
return btn;
};