Jump to content

Recommended Posts

I'm trying to generate a page with javascript in it with PHP.  But the quotations are causing me problems, I need a third set of quotations.  Here is the part I am having trouble with:

 

 

echo"<div class='level'>Edit:</div><div class='box'><input type = 'text'  size='50' name='cat' value='$cat'/> <b><input type='button' value='+ Details' onclick='document.getElementById('rev$clicker').style.display='block';'/></b> </div><br>";

 

 

When I view the html it comes out onclick='document.getElementById('rev$clicker').style.display='block';'

 

I can't use "" quotations for 'block' and 'rev$clicker' because that would exit from the echo and I can't exit php because I need the $clicker variable.

Link to comment
https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/
Share on other sites

You can use \ to "escape" characters, even quotes.  Whatever comes after the \ is "ignored" or hidden so you can use quotes within quotes.

 

Yours would be this:

 

onclick='document.getElementById(\'rev$clicker\').style.display=\'block\';'/>

 

That escape should only work for the php parse as by the time it gets to the browser and js takes over, the slashes should have been processed and tossed.

You may prefer to use heredoc syntax

echo <<<HTML
<div class="level">Edit:</div>
<div class='box'>
  <input type="text"  size="50" name="cat" value="{$cat}"/> <b><input type="button" value="+ Details" onclick="document.getElementById('rev{$clicker}').style.display='block';"/></b>
</div>
<br>
HTML;

No need to worry about what quotes you use. Just type the html as you normally would.

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.