forked from avinriyan/simpleCRUDjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (32 loc) · 1023 Bytes
/
script.js
File metadata and controls
38 lines (32 loc) · 1023 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var data = [
"Rekayasa Perangkat Lunak",
"Teknik Penyempurnaan Tekstil",
"Teknologi Pengolahan Hasil Pertanian",
"Teknik Konstruksi Batu dan Beton"
];
function tampil() {
var tabel = document.getElementById("tabel");
tabel.innerHTML = "<tr><th>No</th><th>Jurusan</th><th>Action</th></tr>";
for (let i = 0; i < data.length; i++) {
var btnEdit = "<button class='btn-edit' href='#' onclick='edit(" + i + ")'>Edit</button>";
var btnHapus = "<button class='btn-hapus' href='#' onclick='hapus(" + i + ")'>Hapus</button>";
j = i + 1;
tabel.innerHTML += "<tr><td>" + j + "</td><td>" + data[i] + "</td><td>" + btnEdit + " " + btnHapus + "</tr>";
}
}
function tambah() {
var input = document.querySelector("input[name=jurusan]");
data.push(input.value);
tampil();
input.value = "";
}
function edit(id) {
var baru = prompt("Edit", data[id]);
data[id] = baru;
tampil();
}
function hapus(id) {
data.pop(id);
tampil();
}
tampil();