Jump to content

Does Java script not like line breaks?


Shadowing

Recommended Posts

I notice if I try to hit enter and split a long string up with java script i get a error.

 

onmouseover="popup('<img src="images/planets/<?php echo $picture; ?>.jpg"/>
<?php echo planet_pop_up($detail_name,$stargate_address,$detail_owner); ?>');">

 

then i have a function being inserted into the code above "planet_pop_up"

the function has this string in it.

$details = "<h4>$detail_name</h4><br /><br /><br /><p>Owner:  $detail_owner</p>";

 

This string is going to get really long cause im going to be adding to it. If i try to bring some of it onto a new line i get a java script error. "Unterminated string constant"

like this below

 

$details = "<h4>$detail_name</h4><br /><br /><br />
<p>Owner:  $detail_owner</p>";

 

anyone know what I need to do to to so i can use more then one line lol.

Link to comment
https://forums.phpfreaks.com/topic/258635-does-java-script-not-like-line-breaks/
Share on other sites

Firstly, you shouldn't be mixing your JavaScript in your markup. There has been for a long time now better way of doing it.

 

As for your question, you need to tell JavaScript to continue a string on a new line. eg;

 

var str = "This is some\
long sttring\
continued over\
multiple lines.

";

thank you thorpe.

 

whats a better way of doing it?

 

or maybe something i can read. Id like to have better technique.

 

one thing i hate is when i started learning all this stuff that i started out building on poor foundations on how im writing.

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.