/    Sign up×
Community /Pin to ProfileBookmark

Problem with embedding JS code in PHP

Hi all,

I have the following string as part of my PHP code (before you ask, it HAS to be in PHP, can’t write PHP and HTML separately):

[code]
$submission_form =”
<p style=”font-size:20px; padding: 15px;”>
<u>Please select the type of analysis you wish to perform</u>
</p>
<form name=”analysis_form” method=”post”>
<div>
<a id=”myHeader1-2″ href=”javascript:showonlyonev2(“newboxes1-2″);” >
<input type=radio name=”criterion” value=”single_genotype”>
Single-study analysis using genotypes
</a>
</div>
[/code]

Everything works fine, except the JS part…Because it should have single quotes, but this I can’t do it inside the PHP string…
Any ideas?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 28.2016 — The HEREDOC syntax can eliminate a lot of that messy escaping of quotes.
[code=php]
$submission_form = <<<EOD

<p style="font-size:20px; padding: 15px;">
<u>Please select the type of analysis you wish to perform</u>
</p>
<form name="analysis_form" method="post">
<div>
<a id="myHeader1-2" href="javascript:showonlyonev2('newboxes1-2');" >
<input type=radio name="criterion" value="single_genotype">
Single-study analysis using genotypes
</a>
</div>

EOD;
// makes sure no leading white-space on the above line!
[/code]
Copy linkTweet thisAlerts:
@ginerjmApr 29.2016 — Besides HEREDOCS, you could also get used to using double and single quotes.

Ex.

$submission_form ="

<p style='font-size:20px; padding: 15px;'>

<u>Please select the type of analysis you wish to perform</u>

</p>";

This will also make your JS coding MUCH simpler.

I didn't ask but I fail to see why you say you can't write php and html separately. The two have absolutely nothing to cause you to say that. One is there to produce the other in dynamic situations. Actually, experienced developers strive to KEEP the html and php separate from each other (as well as JS) to make their products more readable and maintainable, something that you code here could benefit from.
×

Success!

Help @ktsirig 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...