-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (54 loc) · 2.08 KB
/
script.js
File metadata and controls
69 lines (54 loc) · 2.08 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
const entryContainer = document.getElementById('entry-container');
const printButton = document.querySelector(".print");
function updateZebra() {
const rows = entryContainer.querySelectorAll(".form-fields");
rows.forEach((row, index) => {
row.classList.remove("even", "odd");
row.classList.add((index + 1) % 2 === 0 ? "even" : "odd");
});
}
updateZebra();
entryContainer.addEventListener("click", (e) => {
const button = e.target.closest("button");
if (!button) return;
const row = button.closest(".form-fields");
const submitDiv = entryContainer.querySelector(".form-submit");
if (button.classList.contains("add")) {
const newRow = row.cloneNode(true);
newRow.querySelectorAll("input, select").forEach(input => input.value = "");
newRow.querySelector(".output").textContent = "";
entryContainer.insertBefore(newRow, submitDiv);
updateZebra();
}
if (button.classList.contains("minus")) {
const allRows = entryContainer.querySelectorAll(".form-fields");
if (allRows.length > 1) {
row.remove();
updateZebra();
}
}
if (button.classList.contains("reset")) {
row.querySelectorAll("input, select").forEach(input => input.value = "");
const outputDiv = row.querySelector(".output");
if (outputDiv) outputDiv.textContent = "";
}
});
// Handle Submit
entryContainer.querySelector(".submit").addEventListener("click", (e) => {
e.preventDefault();
const rows = entryContainer.querySelectorAll(".form-fields");
rows.forEach(row => {
const reagent = row.querySelector(".reagents").value;
const expirationDate = row.querySelector(".expirationdate").value;
const expirationTime = row.querySelector(".expirationtime").value;
const now = new Date();
const expiration = new Date(`${expirationDate}T${expirationTime}`);
const diffMs = expiration - now;
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
row.querySelector(".output").textContent = diffHours;
console.log("Reagent:", reagent, "Hours Remaining:", diffHours);
});
});
printButton.addEventListener("click", () => {
window.print();
});