MediaWiki:Common.js: Difference between revisions

From John's wiki
Jump to navigation Jump to search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: function sumColumn( id, col ) { console.log( [ id, col ] ); var total = 0; var mytable = docu...")
 
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. */


function sumColumn( id, col ) {
function sum_column( id, col ) {
   console.log( [ id, col ] );
   console.log( [ id, col ] );
   var total = 0;
   var total = 0;

Revision as of 20:49, 26 January 2022

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

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;
}