Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    103
    Thanks
    2
    Thanked 15 Times in 15 Posts

    Only reads first array element

    --------RESOLVED--------
    I am trying to make a finance tracker, but for some reason this code will only output the first transaction:
    Code:
    <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 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.
    Last edited by ohbigrighthand; 09-06-2010 at 07:56 AM. Reason: general stupidity


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •