Jump to content

var html = if(url!=null){echo}


NoDoze

Recommended Posts

I'm really rough with javascript...and need to do this from php:

if (!empty($row['url']))
	{
	echo 'url="' . $row['url'] . '" ';
	}

 

...in javascript...

var html = 
	"<span class='gmap-text-header'>" + name + "</span><br>" +
	if(url!=null)
	{
	document.write("<a href='" + url + "'>Link to Realtime Station</a>" +);
	}
	"</span>";

 

So that if there is no url, it only displays the name. And if there is a url it displays both the name and url.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/209032-var-html-ifurlnullecho/
Share on other sites

You can't throw the result of a conditional in the middle of a string like that.  Try:

 

var html = "<span class='gmap-text-header'>" + name + "</span><br>";

if (url)
{
   html += "<a href='" + url + "'>Link to Realtime Station</a>";
}

html += "</span>";

 

It's just like building a string with PHP.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.