MediaWiki:Common.js: Difference between revisions

From John's wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 22: Line 22:
     if ( ! isNaN( val ) ) { total += val; }
     if ( ! isNaN( val ) ) { total += val; }
   }
   }
   document.getElementById( id + '_sum' ).innerHTML = total.toLocaleString('en-AU');
  console.log( total );
  total = total.toLocaleString('en-AU');
   document.getElementById( id + '_sum' ).innerHTML = total;
}
}

Revision as of 00:04, 27 January 2022

/* Any JavaScript here will be loaded for all users on every page load. */

//console.log( 'Hi from Common.js' );

for ( var i in document.jj5_totals ) {

  var spec = document.jj5_totals[ i ];

  sum_column( spec.id, spec.col );

}

function sum_column( id, col ) {
  console.log( [ id, col ] );
  var total = 0;
  var mytable = document.getElementById( id );
  for ( var v=1; v < mytable.rows.length - 1; v++ ) {
    var val = mytable.rows[v].cells[col].innerHTML;
    console.log( val );
    val = val.replace( '$', '' );
    val = parseFloat( val );
    if ( ! isNaN( val ) ) { total += val; }
  }
  console.log( total );
  total = total.toLocaleString('en-AU');
  document.getElementById( id + '_sum' ).innerHTML = total;
}