Page 1 of 1

Using onclick in PHP

Posted: Tue Mar 17, 2009 3:21 am
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.

Re: Using onclick in PHP

Posted: Tue Mar 17, 2009 3:38 am
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";

Re: Using onclick in PHP

Posted: Tue Mar 17, 2009 3:46 am
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

Re: Using onclick in PHP

Posted: Tue Mar 17, 2009 3:48 am
by kdidymus
Yep. It WAS something simple but couldn't have done it without you.

Thanks. You've saved my sanity.

KD.