From d3e50174b5e1002311cb9ce20dde5f2eb8f54f29 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sat, 6 Jun 2026 06:00:25 +0530 Subject: [PATCH] Fix trailing comma in JavaScript array from PHP foreach BUGFIX: Uncaught SyntaxError expected expression, got ')' PROBLEM: Trailing comma after last array item caused JavaScript syntax error ROOT CAUSE: PHP foreach loop always added comma after each object: {...}, {...}, // <-- trailing comma before ] ]; While modern JS allows trailing commas, some parsers or contexts (like when injected/evaluated) don't handle it well. SOLUTION: Only add comma between items, not after last item: 1. Count total items before loop 2. Track current index in loop 3. Add comma only if currentIndex < itemCount GENERATED JS NOW: [ {...}, {...}, {...} // <-- no trailing comma ] This eliminates the syntax error. --- app/Views/billing/ipd/discharge_create.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Views/billing/ipd/discharge_create.php b/app/Views/billing/ipd/discharge_create.php index 6ea6ea8..e523cc8 100644 --- a/app/Views/billing/ipd/discharge_create.php +++ b/app/Views/billing/ipd/discharge_create.php @@ -1670,7 +1670,12 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller // Load existing complaints from PHP (if any) selectedDischargeComplaints = [ - + { id: , term: , @@ -1678,7 +1683,8 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller severity: '', duration: , date: '' - }, + } + ];