-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
94 lines (85 loc) · 2.97 KB
/
script.js
File metadata and controls
94 lines (85 loc) · 2.97 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
82
83
84
85
86
87
88
89
90
91
92
93
94
let attendancedata =[];
const form = document.querySelector("form");
const rollinput = document.getElementById("roll");
const statusSelect = document.getElementById("status");
const totalCountEl = document.getElementById("totalcount");
const presentCountEl = document.getElementById("presentcount");
const absentCountEl = document.getElementById("absentcount");
let totalcount =0;
let presentcount =0;
let absentcount =0;
const rollnumbers =[];
form.addEventListener("submit",function(event){
event.preventDefault();
const rollnumber = rollinput.value;
const status = statusSelect.value;
if(rollnumber.trim() === ""){
alert("Please enter a roll number");
return;
}
if (rollnumbers.includes(rollnumber)) {
alert("This roll number is already marked!");
return;
}
const newrow =document.createElement("tr");
const namecell = document.createElement("td");
const rollcell = document.createElement("td");
const statuscell = document.createElement("td");
namecell.textContent = "New Student";
rollcell.textContent = rollnumber;
statuscell.textContent = status;
newrow.appendChild(namecell);
newrow.appendChild(rollcell);
newrow.appendChild(statuscell);
tablebody.appendChild(newrow);
rollnumbers.push(rollnumber);
attendancedata.push({
roll : rollnumber,
status: status
});
localStorage.setItem("attendancedata",JSON.stringify(attendancedata));
totalcount++;
totalCountEl.textContent =totalcount;
if (status=="Present") {
presentcount++;
presentCountEl.textContent =presentcount;
}
else{
absentcount++;
absentCountEl.textContent=absentcount;
}
rollinput.value ="";
statusSelect.selectedIndex =0;
});
const tablebody = document.querySelector("tbody");
window.addEventListener("load",function () {
const savedData =this.localStorage.getItem("attendancedata");
if (savedData) {
attendancedata=JSON.parse(savedData);
attendancedata.forEach(function (item) {
const roll =item.roll;
const status = item.status;
const newrow = document.createElement("tr");
const nameCell = document.createElement("td");
const rollCell = document.createElement("td");
const statusCell = document.createElement("td");
nameCell.textContent = "Student";
rollCell.textContent = roll;
statusCell.textContent = status;
newrow.appendChild(nameCell);
newrow.appendChild(rollCell);
newrow.appendChild(statusCell);
tablebody.appendChild(newrow);
totalcount++;
if (status === "Present") {
presentcount++;
} else {
absentcount++;
}
rollnumbers.push(roll);
});
totalCountEl.textContent = totalcount;
presentCountEl.textContent = presentcount;
absentCountEl.textContent = absentcount;
}
});