MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 12: | Line 12: | ||
function sum_column( id, col ) { | function sum_column( id, col ) { | ||
console.log( [ id, col ] ); | //console.log( [ id, col ] ); | ||
var total = 0; | var total = 0; | ||
var mytable = document.getElementById( id ); | var mytable = document.getElementById( id ); | ||
Line 22: | Line 22: | ||
val = parseFloat( val ); | val = parseFloat( val ); | ||
if ( ! isNaN( val ) ) { | if ( ! isNaN( val ) ) { | ||
console.log( val ); | //console.log( val ); | ||
total += val; | total += val; | ||
} | } | ||
} | } | ||
console.log( total ); | //console.log( total ); | ||
total = total.toLocaleString('en-AU'); | total = total.toLocaleString('en-AU'); | ||
document.getElementById( id + '_sum' ).innerHTML = total; | document.getElementById( id + '_sum' ).innerHTML = total; | ||
} | } |
Revision as of 00:12, 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 = val.replace( ',', '' ); val = parseFloat( val ); if ( ! isNaN( val ) ) { //console.log( val ); total += val; } } //console.log( total ); total = total.toLocaleString('en-AU'); document.getElementById( id + '_sum' ).innerHTML = total; }