Using onclick in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kdidymus
Forum Contributor
Posts: 196
Joined: Tue May 13, 2008 3:37 am

Using onclick in PHP

Post by kdidymus »

I'm probably overlooking something REALLY simple.

What I want to do is create a table inside an echo statement which is clickable as a hyperlink.

So what I've come up with is:

Code: Select all

echo "
<table id='test' border='1' cellspacing='0' cellpadding='0' onclick="location='load.php'">
  <tr>
    <td></td>
 </tr>
</table>";
 
The onclick needs the quotation marks but I can't use these inside an echo statement for obvious reasons. I've tried using apostrophes instead but this doesn't work. I've also tried defining the onclick line as a string and calling it but again, the quotation marks are needed.

Any ideas?

KD.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Using onclick in PHP

Post by Mark Baker »

You can include quote marks inside a string, as long as you escape them

Code: Select all

$boxerName = "Thomas \"The Hit Man\" Hearns";
jhack
Forum Newbie
Posts: 10
Joined: Wed Mar 11, 2009 9:46 pm

Re: Using onclick in PHP

Post by jhack »

Code: Select all

 
echo '
<table id="test" border="1" cellspacing="0" cellpadding="0" [b]onclick="location='load.php'"[/b]>
<tr><td></td></tr>
</table>
';
In your code there are misleading quotes. Use single quotes for echo statement and I think it is better to use double quotes instead of single quote when defining HTML tag attributes. your browser will works fine but it does not match with standards. I didn't try this out but it should work fine
kdidymus
Forum Contributor
Posts: 196
Joined: Tue May 13, 2008 3:37 am

Re: Using onclick in PHP

Post by kdidymus »

Yep. It WAS something simple but couldn't have done it without you.

Thanks. You've saved my sanity.

KD.
Post Reply