-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.html
More file actions
117 lines (102 loc) · 3.78 KB
/
log.html
File metadata and controls
117 lines (102 loc) · 3.78 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RFID Input to Table</title>
<style>
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>RFID Input Example</h1>
<!-- Status Selection -->
<button onclick="setStatus('In lab')">In lab</button>
<button onclick="setStatus('At hostel')">At hostel</button>
<p id="status-display">Selected Status: None</p>
<!-- RFID Input Field -->
<input type="text" id="rfid-input" placeholder="Scan RFID tag here" autofocus />
<!-- Clear Button -->
<button onclick="clearTable()">Clear All</button>
<table id="rfid-table">
<thead>
<tr>
<th>RFID Tag</th>
<th>Status</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
const rfidInput = document.getElementById('rfid-input');
const tableBody = document.querySelector('#rfid-table tbody');
const statusDisplay = document.getElementById('status-display');
let selectedStatus = null;
// Set and display the selected status
function setStatus(status) {
selectedStatus = status;
statusDisplay.textContent = `Selected Status: ${status}`;
}
// Add or update RFID data
function addOrUpdateRow(rfidTag) {
if (!selectedStatus) {
alert("Please select a status before scanning.");
return;
}
const timestamp = new Date().toLocaleString();
const storedData = JSON.parse(localStorage.getItem('rfidLogs')) || [];
const existingEntry = storedData.find(entry => entry.rfidTag === rfidTag);
if (existingEntry) {
existingEntry.status = selectedStatus;
existingEntry.timestamp = timestamp;
} else {
storedData.push({ rfidTag, status: selectedStatus, timestamp });
}
localStorage.setItem('rfidLogs', JSON.stringify(storedData));
displayTable();
}
// Display table data
function displayTable() {
const storedData = JSON.parse(localStorage.getItem('rfidLogs')) || [];
tableBody.innerHTML = ''; // Clear the table
storedData.forEach(entry => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${entry.rfidTag}</td>
<td>${entry.status}</td>
<td>${entry.timestamp}</td>
`;
tableBody.appendChild(row);
});
}
// Clear all entries in the table and localStorage
function clearTable() {
localStorage.removeItem('rfidLogs'); // Clear data from localStorage
tableBody.innerHTML = ''; // Clear the table display
alert("All entries have been cleared.");
}
// Listen for Enter key to auto-submit
rfidInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter' && rfidInput.value) {
addOrUpdateRow(rfidInput.value.trim());
rfidInput.value = ''; // Clear the input field
}
});
// Initialize table display on page load
displayTable();
</script>
</body>
</html>