-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptttt.js
101 lines (84 loc) · 3.33 KB
/
scriptttt.js
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
95
96
97
98
99
100
101
const users = [];
// Function to add a user
function addUser() {
// Get form values
const firstName = document.getElementById('firstName').value;
const lastName = document.getElementById('lastName').value;
const dateOfBirth = document.getElementById('dateOfBirth').value;
const placeOfBirth= document.getElementById('placeOfBirth').value;
const gender = document.getElementById('gender').value;
const department = document.getElementById('department').value;
const status = document.getElementById('status').value;
// Check iffields are filled
if (firstName === '' || lastName === '' || dateOfBirth === '' || placeOfBirth === '' ) {
alert('Please fill in both the name and email fields.');
return;
}
// Create a user object with initial attendance set to 'Absent'
const user = {
name: name,
email: email,
attendance: 'Absent', // Default attendance
date: '', // Default date
time: '' // Default time
};
// Add the user object to the users array
users.push(user);
// Update the user select dropdown
updateUserSelect();
// Display the updated list of users
displayUsers();
// Clear form fields
document.getElementById('register-staff-form').reset();
}
// Function to update the user select dropdown
function updateUserSelect() {
const userSelect = document.getElementById('username');
uusername.innerHTML = '<option value="">-- Select a User --</option>'; // Reset options
users.forEach((user, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = user.name;
userSelect.appendChild(option);
});
}
// Function to update attendance, date, and time when a user is selected
function updateAttendance() {
const selectedIndex = document.getElementById('username').value;
if (selectedIndex !== '') {
// Get the current date and time
const now = new Date();
const date = now.toLocaleDateString();
const time = now.toLocaleTimeString();
// Update attendance, date, and time for the selected user
users[selectedIndex].attendance = 'Present';
users[selectedIndex].date = date;
users[selectedIndex].time = time;
// Display the updated list of users
displayUsers();
}
}
// Function to display all users in the table
function displayUsers() {
const tableBody = document.querySelector('#userTable tbody');
tableBody.innerHTML = ''; // Clear existing rows
users.forEach(user => {
const row = document.createElement('tr');
const nameCell = document.createElement('td');
const emailCell = document.createElement('td');
const attendanceCell = document.createElement('td');
const dateCell = document.createElement('td');
const timeCell = document.createElement('td');
nameCell.textContent = user.name;
emailCell.textContent = user.email;
attendanceCell.textContent = user.attendance;
dateCell.textContent = user.date;
timeCell.textContent = user.time;
row.appendChild(nameCell);
row.appendChild(emailCell);
row.appendChild(attendanceCell);
row.appendChild(dateCell);
row.appendChild(timeCell);
tableBody.appendChild(row);
});
}