-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
101 lines (88 loc) · 3.47 KB
/
Copy pathindex.js
File metadata and controls
101 lines (88 loc) · 3.47 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
function filterTable() {
const selected = document.getElementById("filter").value.toLowerCase();
const tableRows = document.querySelectorAll(".table-body tr");
tableRows.forEach(row => {
const category = row.cells[0].innerText.trim().toLowerCase();
if (selected === "all" || category === selected) {
row.style.display = "table-row";
} else {
row.style.display = "none";
}
});
}
document.getElementById("filter").addEventListener("change", filterTable);
let seconds = 0;
let minutes = 0;
let hours = 0;
let isRunning = false;
function startStopButton() {
if (!isRunning) {
isRunning = true;
intervalId = setInterval(() => {
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
if (minutes >= 60) {
minutes = 0;
hours++;
}
}
document.getElementById('startstopbutton').innerText = 'STOP';
let formattedTime = `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")} `;
document.querySelector('.stopwatch').innerText = formattedTime;
}, 1000);
} else {
isRunning = false;
clearInterval(intervalId);
document.getElementById("startstopbutton").innerText = "Start";
}
}
function resetTimer() {
clearInterval(intervalId);
seconds = 0;
minutes = 0;
hours = 0;
document.getElementById("startstopbutton").innerText = "Start";
let formattedTime = `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")} `;
document.querySelector('.stopwatch').innerText = formattedTime;
}
document.getElementById("form-entry").addEventListener("submit", function(event) {
event.preventDefault();
const category = document.getElementById("category").value;
const subCategory = document.getElementById("subCategory").value;
const duration = document.querySelector('.stopwatch').innerText;
const task = document.getElementById("task").value;
const newRow = document.createElement("tr");
newRow.innerHTML = `
<td>${category}</td>
<td>${subCategory}</td>
<td>${duration}</td>
<td>${task}</td>
<td>
<button onclick="updateRow(this)">Update</button>
<button onclick="deleteRow(this)">Delete</button>
</td>
`;
document.querySelector(".table-body").appendChild(newRow);
document.getElementById("form-entry").reset();
resetTimer();
});
/*function updateTimerDisplay() {
let formattedTime = `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")} `;
document.querySelector('.stopwatch').innerText = formattedTime;
}
*/
function updateRow(button) {
const row = button.closest("tr");
const cells = row.querySelectorAll("td");
document.getElementById("category").value = cells[0].innerText.trim();
document.getElementById("subCategory").value = cells[1].innerText.trim();
document.querySelector('.stopwatch').innerText = cells[2].innerText.trim();
document.getElementById("task").value = cells[3].innerText.trim();
row.remove();
}
function deleteRow(button) {
const row = button.closest("tr");
row.remove();
}