Shadowing Posted March 10, 2012 Share Posted March 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258635-does-java-script-not-like-line-breaks/ Share on other sites More sharing options...
trq Posted March 10, 2012 Share Posted March 10, 2012 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. "; Quote Link to comment https://forums.phpfreaks.com/topic/258635-does-java-script-not-like-line-breaks/#findComment-1325791 Share on other sites More sharing options...
Shadowing Posted March 10, 2012 Author Share Posted March 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258635-does-java-script-not-like-line-breaks/#findComment-1325927 Share on other sites More sharing options...
trq Posted March 10, 2012 Share Posted March 10, 2012 There are plenty of libraries around these days which give the ability to us CSS selectors to attach events to specific targets. jQuery is one that comes to mind. Quote Link to comment https://forums.phpfreaks.com/topic/258635-does-java-script-not-like-line-breaks/#findComment-1325997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.