Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
81 lines (72 loc) · 2.23 KB
/
Copy pathscript.js
File metadata and controls
81 lines (72 loc) · 2.23 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function login() {
var usnm = document.getElementById("username1").value;
var pswrd = document.getElementById("password1").value;
const message = document.getElementsByClassName("msg");
if (usnm == "admin" && pswrd == "password123") {
window.location.href = "/pages/list.html";
return false;
} else {
alert("Invalid Username or Password");
}
console.log(login);
}
function added() {
let studentsList = JSON.parse(localStorage.getItem("student_list")) || [];
const task1 = document.getElementById("Target").value;
const task2 = document.getElementById("myselect").value;
const task3 = document.getElementById("Target2").value;
const task4 = document.getElementById("Target3").value;
const newStudent = { name: task1, class: task2, grade: task3, phone: task4 };
studentsList.push(newStudent);
localStorage.setItem("student_list", JSON.stringify(studentsList));
window.location.href = "/pages/list.html";
}
document.addEventListener("DOMContentLoaded", () => {
const inputlist = document.getElementById("tableinput");
if (inputlist) {
let studentsList = JSON.parse(localStorage.getItem("student_list")) || [];
inputlist.innerHTML = `
<table >
<thead >
<tr>
<th>Name</th>
<th>Class</th>
<th>Grade</th>
<th>Phone</th>
<th>Action</th>
</tr>
</thead>
<tbody>
${studentsList
.map(
(list, index) => `
<tr class="main">
<td>${list.name}</td>
<td>${list.class}</td>
<td>${list.grade}</td>
<td>${list.phone}</td>
<td>
<button class="del_btn" onclick="del()" data-index="${index}">Delete</button>
</td>
</tr>
`
)
.join("")}
</tbody>
<tfoot>
<tr>
<td colspan="4">Total</td>
<td>${studentsList.length}</td>
</tr>
</tfoot>
</table>`;
}
});
function del() {
var deld = document.querySelectorAll(".del_btn");
deld.forEach((delet) => {
delet.onclick = () => {
delet.parentElement.parentElement.remove();
};
});
}