Jump to content

Recommended Posts

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?!

Link to comment
https://forums.phpfreaks.com/topic/221388-writing-javascript-in-php/
Share on other sites

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.

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>';

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>

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>';

	}

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?!

 

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.

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.

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.