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
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.

";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.