issue with echo with a a href and onclick

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
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

issue with echo with a a href and onclick

Post by cjkeane »

i'm having a bit of trouble with this line of code. anyone have any ideas? i know its a matter of quotes in the right place.

Code: Select all

<?php
	echo '<td><a href="sr_bytypedetails.php?TypeOfFile='.$result['TypeOfFile'].' onclick="toggle_visibility('details');" > '. $result['TypeOfFile'] .'</a></td>';	

?>
Last edited by cjkeane on Fri May 13, 2011 9:39 am, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: issue with echo with a a href and onclick

Post by John Cartwright »

If you want single quotes inside of single quotes, you need to escape them, or use double quotes.

Code: Select all

 echo '<td><a href="sr_bytypedetails.php?TypeOfFile='.$result['TypeOfFile'].' onclick="toggle_visibility(\'foo\');" > '. $result['TypeOfFile'] .'</a></td>'; 
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: issue with echo with a a href and onclick

Post by cjkeane »

i've reworked it, and i still have an issue.

Code: Select all

<?php
echo '<td><a href="sr_bytype.php?TypeOfFile='.$result['TypeOfFile'] . ' onclick="document.getElementById('\foo\').style.display=(document.getElementById('\foo\').style.display=='\block\')?\'none\':'\block\';"> '. $result['TypeOfFile'] .'</a></td>';
?>

John Cartwright wrote:If you want single quotes inside of single quotes, you need to escape them, or use double quotes.

Code: Select all

 echo '<td><a href="sr_bytypedetails.php?TypeOfFile='.$result['TypeOfFile'].' onclick="toggle_visibility(\'foo\');" > '. $result['TypeOfFile'] .'</a></td>'; 
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: issue with echo with a a href and onclick

Post by Celauran »

Your last 'block' bit doesn't have the opening single quote escaped; the backslash is after the quote, not before it.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: issue with echo with a a href and onclick

Post by John Cartwright »

Look carefully at the position of my escaping backslash, and the position of where you put the escaping backslash.
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: issue with echo with a a href and onclick

Post by cjkeane »

i see my problem. thanks! issue has been resolved!
Post Reply