Click to See Complete Forum and Search --> : attempting to build running totals using arrays


hoonak
01-23-2003, 09:23 PM
I am building a web site that tracks government activity. I want to put javascripts on it that will "spit out" updated totals every day, but I do not want to re-write the html all the time. I hope to use a javascript and pull the running total from an array. I think I am close, but I cannot quite get there.
var presDocs03 = new Array();
presDocs03 [0] = 0; //new year's day
presDocs03 [1] = 0;
presDocs03 [2] = 0;
presDocs03 [3] = 0; //saturday
presDocs03 [4] = 0; //sunday
presDocs03 [5] = 1;
presDocs03 [6] = 0;
presDocs03 [7] = 2;
presDocs03 [8] = 0;
presDocs03 [9] = 0;
presDocs03 [10] = 0; //saturday
presDocs03 [11] = 0; //sunday


var totPresDocs03 = 0;
function presDocs03TotPgs() {
for (var i=0; i<presDocs03.length; i++) {
totPresDocs03 += presDocs03[ i ];
}
window.status = "presDocs03TotPgs = "+totPresDocs03;
} commented out until status

[CODE]

The function will be called with
[CODE]<body onLoad=presDocs03TotPgs():></body>

any comments or suggestions appreciated.

khalidali63
01-23-2003, 09:30 PM
it looks like youve got it .

just replace this line
<body onLoad=presDocs03TotPgs():></body>
with this

<body onLoad="presDocs03TotPgs();">

cheers

Khalid

hoonak
01-25-2003, 02:54 AM
to khalidali63:
thanks man!