diff --git a/index.php b/index.php index e84ee26..b75dd1c 100644 --- a/index.php +++ b/index.php @@ -352,7 +352,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
- + cc
@@ -630,11 +630,29 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { /* darah */ + function sumDarah() { + + let inputs = document.querySelectorAll('input[name="jumlah_darah[]"]') + let total = 0 + + inputs.forEach(input => { + let val = parseFloat(input.value) + if (!isNaN(val)) { + total += val + } + }) + + document.querySelector('input[name="sum_darah"]').value = total + } + document.addEventListener("click", e => { if (e.target.classList.contains("addDarah")) { let row = document.querySelector(".darahRow").cloneNode(true) + + row.querySelector('input[name="jumlah_darah[]"]').value = "" + document.getElementById("darahContainer").appendChild(row) } @@ -645,12 +663,21 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { if (rows.length > 1) { e.target.closest(".darahRow").remove() + sumDarah() } } }) + document.addEventListener("input", function(e) { + + if (e.target.name === "jumlah_darah[]") { + sumDarah() + } + + }) + /* specimen */ document.addEventListener("click", e => {