469,344 Members | 6,204 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

Addition When Null value is present

I'm having trouble adding two values together when one of them has a
null value

// These two values come from a database
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null
This should alert to true but doesn't

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
CEONonEqIncentCompHidden < 2264001)
{
alert("true");
TotalScore = TotalScore + 2.5;
}

If I do this then it works fine.

CEOBonusValue == 550000
CEONonEqIncentCompHidden == 0

I'm not sure how to handle this. I need to keep the null values in my
database.

Thanks

May 25 '07 #1
2 1994
On May 25, 7:06 pm, shankwheat <evanbu...@gmail.comwrote:
I'm having trouble adding two values together when one of them has a
null value

// These two values come from a database
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null

This should alert to true but doesn't

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
CEONonEqIncentCompHidden < 2264001)
{
alert("true");
TotalScore = TotalScore + 2.5;
}

If I do this then it works fine.

CEOBonusValue == 550000
CEONonEqIncentCompHidden == 0

I'm not sure how to handle this. I need to keep the null values in my
database.

Thanks
Wait a minute, how does this javascript piece of code actually gets
this string "null", if the "null" value travels through server-side
code, and gets printed to javascript. What I mean is, if you get the
value from db in e.g. php, can't you just check immediately if the
value is null, and if it is - print it to javascript as 0? Why do you
print "null" to javascript, if you can't handle it well?

Another thing, I don't know if it's bad syntax just here in the thread
or you did the same in your scripts, but it seams you've been mixing
"==" and "=" operators... I see the piece of code:
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null
- the second line isn't of much use, it should be ...dden = null,
not ...den == null (because in this way you don't actually assign it,
but just compare it)...

May 25 '07 #2
On May 25, 10:06 am, shankwheat <evanbu...@gmail.comwrote:
I'm having trouble adding two values together when one of them has a
null value

// These two values come from a database
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null

This should alert to true but doesn't

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
CEONonEqIncentCompHidden < 2264001)
The unary + operator will convert a null to numeric zero. E.g., you
could write:

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
+CEONonEqIncentCompHidden < 2264001)

to cover off the problem as described (misuse of == notwithstanding).

--
../rh

May 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.