heldenbrau Posted August 15, 2010 Share Posted August 15, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/ Share on other sites More sharing options...
sinista Posted August 15, 2010 Share Posted August 15, 2010 can you use " with a \ in front of it i.e. (\"re ? Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099614 Share on other sites More sharing options...
linus72982 Posted August 15, 2010 Share Posted August 15, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099617 Share on other sites More sharing options...
wildteen88 Posted August 15, 2010 Share Posted August 15, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099618 Share on other sites More sharing options...
heldenbrau Posted August 15, 2010 Author Share Posted August 15, 2010 Thanks, I forgot about using \ to escape. For the echo<<<HTML thing, how do you exit it? When I end with HTML; it doesn't exit. Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099620 Share on other sites More sharing options...
wildteen88 Posted August 15, 2010 Share Posted August 15, 2010 It does exit, Its just this forum seems to have an issue parsing HEREDOC properly. Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099622 Share on other sites More sharing options...
heldenbrau Posted August 15, 2010 Author Share Posted August 15, 2010 I have tried running the web page but there is an error because it won't come out of html after the <<<HTML bit. Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099625 Share on other sites More sharing options...
wildteen88 Posted August 15, 2010 Share Posted August 15, 2010 Make sure you don't have anything on the same as HTML;, this includes whitespace characters such as a space or tabs etc. Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099626 Share on other sites More sharing options...
heldenbrau Posted August 15, 2010 Author Share Posted August 15, 2010 Thanks, that's done it, the javascript is working now. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/210801-generating-a-page-with-javascript-in-it/#findComment-1099629 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.