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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sum values if any as a NULL

    Hi, I have a table with some values and this part of code do a sum.
    Actually I have the problem that if any value in a cell is NULL the result (the sum) i "n/a".

    What's need in this code to assign a "0" value if my cell is NULL?


    Code:
    if(this.p.sum){
        r=this.newrow(f);
        for(i;i<t.w;i++){
            var j=r.cells[i];
            if(this.p.sum.exists(i)){
            var s=0, m=t.c[i].format||'';
            for(x=0;x<this.t.l;x++){
                if(t.a[x].s){s+=parseFloat(t.r[x].cells[i].innerHTML.replace(/(\$|\,)/g,''))}
            }
                s=decimals(s,t.c[i].decimals?t.c[i].decimals:2);
                    s=isNaN(s)?'n/a':m=='$'?s=s.currency(t.c[i].decimals):s+m;
                       r.cells[i].innerHTML=s
                   }else{r.cells[i].innerHTML='&nbsp;'}
            }
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Code:
    var a = null;
    if (!a) {a =0}
    alert (a);
    It was always going to be a game of nutrition. - Commentator Radio Scotland

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In which part?
    My value is the var "s". It's necessary to assign a null value?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by guif View Post
    In which part?
    My value is the var "s". It's necessary to assign a null value?
    That was just an example. If the value of the variable I named a and you name s is null, change the value to 0.

    if (!s) {s=0}
    Last edited by Philip M; 01-04-2013 at 11:48 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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