-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop.js
34 lines (28 loc) · 1.01 KB
/
oop.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
class FormTable {
constructor(formId, tableId) {
this.form = document.getElementById(formId);
this.table = document.getElementById(tableId);
this.tbody = this.table.querySelector('tbody');
}
dataMasuk() {
const nama = this.form.elements.nama.value;
const umur = this.form.elements.umur.value;
const uangSaku = this.form.elements.uangSaku.value;
if (nama && umur && uangSaku) {
const newRow = this.tbody.insertRow();
const cellNama = newRow.insertCell(0);
const cellUmur = newRow.insertCell(1);
const celluangSaku = newRow.insertCell(2);
cellNama.textContent = nama;
cellUmur.textContent = umur;
celluangSaku.textContent= uangSaku;
this.form.reset(); // Clear the form fields
} else {
alert('Harap isi semua kolom formulir.');
}
}
}
const formTable = new FormTable('myForm', 'myTable');
function dataMasuk() {
formTable.dataMasuk();
}