Jump to content

[SOLVED] Having problems echoing HTML tag with javascript in it


Recommended Posts

Trying to echo a HTML tag that has variables in it.

 

Kinda beating my head on the wall with this one unfortunately. How to I echo the anchor text with the ' and " in it.

$output = $row['services_address'] . $row['services_address_2'] . $row['services_city'] . $row['services_state'];

echo '<a href ="maps.php?address='.$output.'" onClick="window.open('maps.php?address='.$output.'','Page Name','height=500,width=500,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');">View Map</a>';

you need to escape all those single quotes inside your onClick part.

 

better yet, use heredoc so you don't have to worry about escaping quotes:

 

echo <<<EOF
<a href ="maps.php?address={$output}" onClick="window.open('maps.php?address={$output}','Page Name','height=500,width=500,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');">View Map</a>
EOF;

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.