jarv Posted December 12, 2010 Share Posted December 12, 2010 I don't think the start of my code is right?! echo '<button onclick=\"gohere(viewpub.php?PubID='.$row['PubID'].')" id="button" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">View Pub</span></button>'; Please help?! Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/ Share on other sites More sharing options...
Anti-Moronic Posted December 12, 2010 Share Posted December 12, 2010 I won't rewrite the line for you, but I can tell you that you don't have to escape double quotes inside single quotes or vice versa. You only escape if you are using the same type of quotes. ESCAPE: ' \'some string\' ' " \"somestring\" " DON'T ESCAPE " 'somestring' " ' "somestring" ' With that, correct your string. Also, try to echo out that html and see the source code, make sure it is valid html. To give you a headstart onclick=\" You don't need to escape that double quote for reason above - your string is encased in single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146166 Share on other sites More sharing options...
jarv Posted December 12, 2010 Author Share Posted December 12, 2010 this is doing my head in... I have this after 20 minutes and it still doesn't work?! echo '<button onclick=\"gohere("viewpub.php?PubID='.$row['PubID'].'\")" id="button" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">View Pub</span></button>'; Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146200 Share on other sites More sharing options...
RichardRotterdam Posted December 12, 2010 Share Posted December 12, 2010 Try it the other way around so it's easier to read. <button id="button" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"> <span onclick="<?php echo "gohere('viewpub.php?PubID={$row['PubID']})" ?>" class="ui-button-text">View Pub</span> </button> Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146211 Share on other sites More sharing options...
jarv Posted December 12, 2010 Author Share Posted December 12, 2010 this confuses me even more, thanks anyway but there are 3 lines of code echoed out while($row = mysql_fetch_array($result)) { echo '<div><h3><a href=\"#\">'.$row['rsPubName'].', '.$row['rsTown'].'</a></h3><div>'.$row['rsAddress'].'<br />'.$row['rsTown'].', '.$row['rsCounty'].'<br />'.$row['rsPostCode'].'<br /><br />Region: '.$row['Region'].'<br /><br />Telephone: '.$row['rsTel'].'<br /><br />'; echo '<button onclick=\"gohere(viewpub.php?PubID='.$row['PubID'].')"\" id="button" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">View Pub</span></button>'; echo '<br /><br /><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.mypubspace.com/default.php?PubID='.$row['PubID'].'%2F&layout=standard&show_faces=true&width=400&action=recommend&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:400px; height:80px;" allowTransparency="true"></iframe></div></div>'; } Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146217 Share on other sites More sharing options...
Anti-Moronic Posted December 12, 2010 Share Posted December 12, 2010 Did you just ignore my message? I told you exactly why it isn't working. Did you ignore Dj Kats message to? He provided a BETTER way of doing it. Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146220 Share on other sites More sharing options...
jarv Posted December 12, 2010 Author Share Posted December 12, 2010 Why would I ignore your help?! I spent 20 minutes trying what you suggested, I tried: echo '<button onclick=\"gohere(viewpub.php?PubID='.$row['PubID'].')"\" ...... echo '<button onclick=\"gohere("viewpub.php?PubID='.$row['PubID'].'")"\" ...... echo '<button onclick=\"gohere(\"viewpub.php?PubID='.$row['PubID'].'\")"\" ...... None of these work then I tried echo '<button onclick="';?><?php echo "gohere('viewpub.php?PubID={$row['PubID']})" ?>" <? echo '...... and that didn't work?! Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146229 Share on other sites More sharing options...
BlueSkyIS Posted December 12, 2010 Share Posted December 12, 2010 you don't have to escape double quotes inside single quotes or vice versa. You only escape if you are using the same type of quotes. ESCAPE: ' \'some string\' ' " \"somestring\" " DON'T ESCAPE " 'somestring' " ' "somestring" ' With that, correct your string. Also, try to echo out that html and see the source code, make sure it is valid html. To give you a headstart onclick=\" You don't need to escape that double quote for reason above - your string is encased in single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146251 Share on other sites More sharing options...
jarv Posted December 12, 2010 Author Share Posted December 12, 2010 so, something like this?: echo '<button onclick=\"gohere(\'viewpub.php?PubID='.$row['PubID'].'\')\"... which also doesn't work?! my page is stuck now?! Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146254 Share on other sites More sharing options...
jarv Posted December 12, 2010 Author Share Posted December 12, 2010 ok, I've got it, echo '<button onclick="gohere(\'viewpub.php?PubID='.$row['PubID'].'\')" thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146255 Share on other sites More sharing options...
Anti-Moronic Posted December 12, 2010 Share Posted December 12, 2010 ok, I've got it, echo '<button onclick="gohere(\'viewpub.php?PubID='.$row['PubID'].'\')" thanks for your help! Glad you got it sorted! Sorry, I thought my message was explanatory enough without having to show you the exact code. Let us know if you have any other problems! Be glad to help. Quote Link to comment https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/#findComment-1146264 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.