File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,17 +125,22 @@ <h4>Overall Results</h4>
125125 function calculateTotal ( ) {
126126 let total = 0 ;
127127 scoreFields . forEach ( function ( fieldId ) {
128- const value = parseInt ( document . getElementById ( fieldId ) . value ) || 0 ;
129- total += value ;
128+ const field = document . getElementById ( fieldId ) ;
129+ if ( field ) {
130+ const value = parseInt ( field . value , 10 ) || 0 ;
131+ total += value ;
132+ }
130133 } ) ;
131134 document . getElementById ( 'total_score' ) . value = total ;
132135 }
133136
134137 // Add event listeners to all score fields
135138 scoreFields . forEach ( function ( fieldId ) {
136139 const field = document . getElementById ( fieldId ) ;
137- field . addEventListener ( 'input' , calculateTotal ) ;
138- field . addEventListener ( 'change' , calculateTotal ) ;
140+ if ( field ) {
141+ field . addEventListener ( 'input' , calculateTotal ) ;
142+ field . addEventListener ( 'change' , calculateTotal ) ;
143+ }
139144 } ) ;
140145} ) ;
141146</ script >
You can’t perform that action at this time.
0 commit comments