MediaWiki:Common.js: Difference between revisions

From John's wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


console.log( 'Hi from Common.js' );
//console.log( 'Hi from Common.js' );
 
for ( let spec of document.jj5_totals ) {
 
  sum_column( spec.id, spec.col );
 
}


function sum_column( id, col ) {
function sum_column( id, col ) {

Revision as of 00:00, 27 January 2022

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

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

for ( let spec of document.jj5_totals ) {

  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; }
  }
  document.getElementById( id + '_sum' ).innerHTML = total;
}