diff --git a/public/js/calculators.js b/public/js/calculators.js
index 9910b6b..905c084 100644
--- a/public/js/calculators.js
+++ b/public/js/calculators.js
@@ -1151,9 +1151,12 @@
return;
}
- var rawAge = (document.getElementById('growth-age').value || '').trim();
- var age = parseAgeMonths(rawAge); // age in months, may be fractional
- if (age == null || isNaN(age) || age < 0) { showToast('Enter age (e.g. 2y 5m, 29 months, 15 days)', 'error'); return; }
+ var yr = parseFloat((document.getElementById('growth-age-yr') || {}).value) || 0;
+ var mo = parseFloat((document.getElementById('growth-age-mo') || {}).value) || 0;
+ var dy = parseFloat((document.getElementById('growth-age-d') || {}).value) || 0;
+ var age = yr * 12 + mo + dy / 30.4375; // age in months, fractional OK
+ if (!age && yr === 0 && mo === 0 && dy === 0) { showToast('Enter age (years, months, or days)', 'error'); return; }
+ if (age < 0) { showToast('Age cannot be negative', 'error'); return; }
if (currentGrowthType === 'wfa') {
var wt = parseFloat(document.getElementById('growth-weight').value);
@@ -1252,26 +1255,29 @@
});
document.getElementById('btn-clear-growth').addEventListener('click', function() {
- ['growth-sex', 'growth-age', 'growth-ga', 'growth-weight', 'growth-length', 'growth-hc'].forEach(function(id) {
+ ['growth-sex', 'growth-age-yr', 'growth-age-mo', 'growth-age-d', 'growth-ga', 'growth-weight', 'growth-length', 'growth-hc'].forEach(function(id) {
var el = document.getElementById(id); if (el) el.value = '';
});
var hint = document.getElementById('growth-age-parsed'); if (hint) hint.textContent = '';
document.getElementById('growth-result').classList.add('hidden');
});
- // Live feedback as user types the age
- var ageEl = document.getElementById('growth-age');
+ // Live feedback as the age fields change
var ageHint = document.getElementById('growth-age-parsed');
- if (ageEl && ageHint) {
- ageEl.addEventListener('input', function() {
- var v = ageEl.value.trim();
- if (!v) { ageHint.textContent = ''; return; }
- var m = parseAgeMonths(v);
- if (m == null || isNaN(m) || m < 0) { ageHint.textContent = 'Unrecognized format'; ageHint.style.color = '#ef4444'; return; }
- ageHint.style.color = 'var(--g500)';
- ageHint.textContent = formatParsedAge(m);
- });
+ function updateAgeHint() {
+ if (!ageHint) return;
+ var yr = parseFloat((document.getElementById('growth-age-yr') || {}).value) || 0;
+ var mo = parseFloat((document.getElementById('growth-age-mo') || {}).value) || 0;
+ var dy = parseFloat((document.getElementById('growth-age-d') || {}).value) || 0;
+ if (!yr && !mo && !dy) { ageHint.textContent = ''; return; }
+ var total = yr * 12 + mo + dy / 30.4375;
+ ageHint.style.color = 'var(--g500)';
+ ageHint.textContent = formatParsedAge(total);
}
+ ['growth-age-yr', 'growth-age-mo', 'growth-age-d'].forEach(function(id) {
+ var el = document.getElementById(id);
+ if (el) el.addEventListener('input', updateAgeHint);
+ });
// ═══════════════════════════════════════════════════════════
// BILIRUBIN — AAP 2022 Phototherapy + Bhutani Nomogram