File size: 2,106 Bytes
165ea77
1e219b4
165ea77
 
f87b9e8
165ea77
f87b9e8
 
 
 
 
 
 
 
165ea77
 
 
f87b9e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165ea77
 
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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Dosage Calculator</title>
  <style>
    body { font-family: sans-serif; max-width: 420px; margin: 40px auto; padding: 0 16px; }
    h1 { font-size: 22px; }
    label { display: block; margin-top: 14px; font-weight: bold; }
    input { width: 100%; padding: 8px; font-size: 16px; margin-top: 4px; box-sizing: border-box; }
    button { margin-top: 18px; padding: 10px 20px; font-size: 16px; cursor: pointer; }
    #result { margin-top: 20px; font-size: 18px; }
    .error { color: #c00; }
    .disclaimer { margin-top: 28px; font-size: 13px; color: #555; border-top: 1px solid #ccc; padding-top: 12px; }
  </style>
</head>
<body>
  <h1>Dosage Calculator</h1>

  <label>Patient weight (kg)</label>
  <input type="number" id="weight" min="0" step="0.1">

  <label>Dose (mg/kg/day)</label>
  <input type="number" id="dosePerKg" min="0" step="0.1">

  <label>Number of doses per day</label>
  <input type="number" id="dosesPerDay" min="1" step="1">

  <button onclick="calculate()">Calculate</button>

  <div id="result"></div>

  <p class="disclaimer">Teaching prototype only. Not for clinical use. Verify every dose independently.</p>

  <script>
    function calculate() {
      const weight = parseFloat(document.getElementById('weight').value);
      const dosePerKg = parseFloat(document.getElementById('dosePerKg').value);
      const dosesPerDay = parseInt(document.getElementById('dosesPerDay').value);
      const result = document.getElementById('result');

      if (isNaN(weight) || isNaN(dosePerKg) || isNaN(dosesPerDay) ||
          weight <= 0 || dosePerKg <= 0 || dosesPerDay <= 0) {
        result.innerHTML = '<span class="error">Enter valid positive numbers in all fields.</span>';
        return;
      }

      const totalDaily = weight * dosePerKg;
      const perDose = totalDaily / dosesPerDay;

      result.innerHTML =
        'Total daily dose: <b>' + totalDaily.toFixed(1) + ' mg/day</b><br>' +
        'Per dose: <b>' + perDose.toFixed(1) + ' mg</b> (' + dosesPerDay + ' times/day)';
    }
  </script>
</body>
</html>