Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2013, 09:07 AM   PM User | #1
guif
New Coder

 
Join Date: Jul 2008
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
guif is an unknown quantity at this point
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;'}
        }
}
guif is offline   Reply With Quote
Old 01-04-2013, 09:56 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 01-04-2013, 10:19 AM   PM User | #3
guif
New Coder

 
Join Date: Jul 2008
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
guif is an unknown quantity at this point
In which part?
My value is the var "s". It's necessary to assign a null value?
guif is offline   Reply With Quote
Old 01-04-2013, 11:46 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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}
__________________

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.

Last edited by Philip M; 01-04-2013 at 11:48 AM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:05 AM.


Advertisement
Log in to turn off these ads.