Jump to content

Generating a page with javascript in it


heldenbrau

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.

Archived

This topic is now archived and is closed to further replies.

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