/    Sign up×
Community /Pin to ProfileBookmark

Javascript and PHP

Hi Guys,

Im using javascript with php, and all is going well, but i’m trying to tidy my code I have this which works great:

[code]
tickercontent[0]='<?
// php select statement
?>
<img class=”mainStoryImage” src=”<? echo $parentSite; ?><?echo $topImagepic; ?>” alt=”Top <? echo $sectionName; ?> story” /><p class=”topstory”><a href=”<? echo $fullURL; ?>articles/1/<? echo $topID; ?>” title=”View Article”><? echo $topHeadline; ?></a></p>’
[/code]

But I want to put the html on two lines like so:

[code]
tickercontent[0]='<?
// php select statement
?>
<img class=”mainStoryImage” src=”<? echo $parentSite; ?><?echo $topImagepic; ?>” alt=”Top <? echo $sectionName; ?> story” />

<p class=”topstory”><a href=”<? echo $fullURL; ?>articles/1/<? echo $topID; ?>” title=”View Article”><? echo $topHeadline; ?></a></p>’
[/code]

However the Javascript then stops working. How can I break the lines?

Thanks

Chris

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 15.2008 — You need to avoid the line break (between IMG and P elements) which in javascript may be interpreted as the end of the line
<i>
</i>tickercontent[0]='&lt;?
// php select statement
?&gt;
&lt;img class="mainStoryImage" src="&lt;? echo $parentSite; ?&gt;&lt;?echo $topImagepic; ?&gt;" alt="Top &lt;? echo $sectionName; ?&gt; story" /&gt;&lt;p class="topstory"&gt;&lt;a href="&lt;? echo $fullURL; ?&gt;articles/1/&lt;? echo $topID; ?&gt;" title="View Article"&gt;&lt;? echo $topHeadline; ?&gt;&lt;/a&gt;&lt;/p&gt;'
Copy linkTweet thisAlerts:
@chrisbauthorApr 15.2008 — Thanks,

But that's what I'm getting at. That huge line of code looks messy to me, so is there any way I can break it up onto two seperate lines?
Copy linkTweet thisAlerts:
@KorApr 15.2008 — Maybe you could echo all the lines in php:
<i>
</i>tickercontent[0]=&lt;? echo
''&lt;img class="mainStoryImage" src="'. $parentSite .''. $topImagepic .'" alt="Top '. $sectionName .' story" /&gt;';
?&gt;
&lt;? echo
'&lt;p class="topstory"&gt;&lt;a href="'. $fullURL .'articles/1/'. $topID .'" title="View Article"&gt;'. $topHeadline .'&lt;/a&gt;&lt;/p&gt;';';
?&gt;
Copy linkTweet thisAlerts:
@KorApr 15.2008 — or you may concatenate the value:
<i>
</i>tickercontent[0]='&lt;?
// php select statement
?&gt;
&lt;img class="mainStoryImage" src="&lt;? echo $parentSite; ?&gt;&lt;?echo $topImagepic; ?&gt;" alt="Top &lt;? echo $sectionName; ?&gt; story" /&gt;';

tickercontent[0]+='&lt;p class="topstory"&gt;&lt;a href="&lt;? echo $fullURL; ?&gt;articles/1/&lt;? echo $topID; ?&gt;" title="View Article"&gt;&lt;? echo $topHeadline; ?&gt;&lt;/a&gt;&lt;/p&gt;';
×

Success!

Help @chrisb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...