Skip to content

Commit

Permalink
Update attandence.html
Browse files Browse the repository at this point in the history
  • Loading branch information
Soujanya2004 authored Feb 17, 2024
1 parent 7a39722 commit 5e2c0e8
Showing 1 changed file with 1 addition and 69 deletions.
70 changes: 1 addition & 69 deletions attandence.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,75 +32,7 @@ <h2>Attendance Table</h2>
</table>
</div>


<script>
let students = [];

function addStudent() {
const studentName = document.getElementById('studentName').value;
if (studentName.trim() === '') {
alert('Please enter a valid student name.');
return;
}

const student = {
name: studentName,
attendance: []
};

students.push(student);
updateAttendanceTable();
document.getElementById('studentName').value = '';
}

function markAttendance(index, isPresent) {
const date = new Date();
const time = date.toLocaleTimeString();
const student = students[index];
const attendanceRecord = {
date: date.toLocaleDateString(),
time,
isPresent

};

student.attendance.push(attendanceRecord);
updateAttendanceTable();
}


function updateAttendanceTable() {
const tableBody = document.getElementById('attendanceBody');
tableBody.innerHTML = '';


students.forEach((student, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="txt">${student.name}</td>
<td class="txt"></td>
<td class="txt"></td>
<td ><button id="btnp" class="btn" onclick="markAttendance(${index}, true)">Present</button></td>
<td><button class="btna" onclick="markAttendance(${index}, false)">Absent</button></td>
<td class="txt"></td>
`;
tableBody.appendChild(row);

const lastRecord = student.attendance[student.attendance.length - 1];


if (lastRecord) {
row.children[1].innerText = lastRecord.date;
row.children[2].innerText = lastRecord.time;

row.children[5].innerText = lastRecord.isPresent;

}

});
}
</script>
<script src="script1.js"></script>
</body>
</html>

Expand Down

0 comments on commit 5e2c0e8

Please sign in to comment.