...

View Full Version : Only reads first array element



ohbigrighthand
09-06-2010, 06:40 AM
--------RESOLVED--------
I am trying to make a finance tracker, but for some reason this code will only output the first transaction:


<html>
<head>
<style>
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
</style>
<script type="text/javascript">

var finance={
ls : localStorage,
codes : new Array(),
getCodes : function (){
finance.codes=(eval("["+finance.ls.code+"]"))
return finance.codes;
},
dates : new Array(),
getDates : function (){
finance.dates=(eval("["+finance.ls.dates+"]"))
return finance.dates;
},
desc : new Array(),
getDescs : function (){
finance.desc=(eval("["+finance.ls.desc+"]"))
return finance.desc;
},
change : new Array(),
getChanges : function (){
finance.change=(eval("["+finance.ls.change+"]"))
return finance.change;
},
getAll : function(){
var t=new Array();
t[0]=finance.getCodes();
t[1]=finance.getDates();
t[2]=finance.getDescs();
t[3]=finance.getChanges();
return t;
},
getRows : function(){
var temp=new Array();
var bal=0;
for (i=0;i<finance.getAll()[0].length;i++){
bal+=finance.getAll()[3][i];
var temp3=document.createElement("tr");
var temp4=new Array();
for(a=0;a<6;a++){
temp4[a]=(document.createElement("td"))
}
temp4[0].innerHTML=finance.getAll()[0][i];
temp4[1].innerHTML=finance.getAll()[1][i];
temp4[2].innerHTML=finance.getAll()[2][i];
temp4[3].innerHTML=((finance.getAll()[3][i]>0)?"":finance.getAll()[3][i]);
temp4[4].innerHTML=((finance.getAll()[3][i]<0)?"":finance.getAll()[3][i]);
temp4[5].innerHTML=bal;
for(i=0;i<6;i++){
temp3.appendChild(temp4[i]);
}
temp.push(temp3);
}
for(i=0;i<temp.length;i++){
document.getElementById("fin").appendChild(temp[i]);
}
}
}
localStorage.code='"&nbsp;","1001","DC"';
localStorage.dates='"&nbsp;","8/30/2010","9/4/2010"';
localStorage.desc='"Starting","Check for Bob","ATM"';
localStorage.change='100,-10,-20';
</script>
</head>
<body onload="finance.getRows();">
<table id="fin">
<tr><th>Code</th><th>Date</th><th>Description</th><th>Payment</th><th>Deposit</th><th>Balance</th></tr>
</table>
</body>
</html>


hahahahaha wow im dumb :p i forgot that nesting two for statements that use "i" is a nono :)
also i know the code may be sloppy, i am just building it now, i will clean it up later. ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum