I am trying to generate some HTML content for Google Maps infowindow. I have 7 values ββthat should be displayed if they are not zero, undefined or "" (empty string).
But apparently my if(e.Property != null || e.Property != "undefined" || e.Property == "")
does not work if Property
is undefined
. Basically, e.Email
is undefined. So instead of skipping this part, my code still inserts the html + "<br />
. And when I alert()
, e.Email returns undefined
, which it should catch and skip if it is.
I tried writing if(typeof e.Property != null || typeof e.Property != "undefined" || typeof e.Property == "")
, but that didn't matter.
// 'e ' is JSON object var generateHTML = { init: function(e) { if (e != null || e != "undefined"){ generateHTML.check(e); } }, check: function (e) { if(e.Title != null || e.Title != "undefined" || e.Title == ""){ html = html + "<b>"+e.Title+"</b>"; } if(e.Address != null || e.Address != "undefined" || e.Address == ""){ html = html +"<br />"+ e.Address; } if(e.Zipcode != null || e.Zipcode != "undefined" || e.Zipcode == ""){ html = html +"<br />"+ e.Zipcode+", "; } if(e.City != null || e.City != "undefined" || e.City == ""){ html = html + e.City; } if(e.Phone != null || e.Phone != "undefined" || e.Phone == ""){ html = html +"<br />"+ e.Phone; } if(e.Email != null || e.Email != "undefined" || e.Email == ""){ html = html +"<br />"+ e.Email; } if(e.WebAddress != null || e.WebAddress != "undefined" || e.WebAddress == ""){ html = html +"<br />"+ e.WebAddress; } return html; } };
diceler
source share