Reputation: 1022
How do you make a numeric variable in javascript return 0 instead of null ?
I have a statistics table for users queries.. When a search criteria is 0 it is returned as null in the JSON object and displayed null in my table.. I was wondering if there's any workaround
e.g
SELECT
SUM( CASE WHEN
table.
color= 'red' THEN 1 ELSE 0 END ) AS 'Red',
SUM( CASE WHEN
Table.
color= 'Blue' THEN 1 ELSE 0 END ) AS 'Blue', ect....
var RedShirts = Stats.Red ;
$("#Red").text(RedShirts);
It bothers me when it displays null instead of 0.. Thanks
Upvotes: 0
Views: 122
Reputation: 754
try
if(RedShirts){
$("#Red").text(RedShirts);
}
else{
$("#Red").text("0");}
Upvotes: 0