-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (27 loc) · 1007 Bytes
/
Copy pathscript.js
File metadata and controls
32 lines (27 loc) · 1007 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
let id = 1;
function addEmployee() {
const name = document.getElementById("name").value;
const salary = document.getElementById("salary").value;
const department = document.getElementById("department").value;
const position = document.getElementById("position").value;
if (!name || !salary || !department || !position) {
alert("Please fill all fields");
return;
}
const tableBody = document.getElementById("tableBody");
const noData = document.getElementById("noData");
if (noData) noData.remove();
const row = document.createElement("tr");
row.innerHTML = `
<td>${id++}</td>
<td>${name}</td>
<td>${salary}</td>
<td>${department}</td>
<td>${position}</td>
<td>
<button class="delete" onclick="this.parentElement.parentElement.remove()">Delete</button>
</td>
`;
tableBody.appendChild(row);
document.querySelectorAll("input").forEach((input) => (input.value = ""));
}