Jump to content

Quote woes with PHP+JS


Adeus

Recommended Posts

Hello. First off, my experience with merging JS+PHP is minimal, so this may be an easy fix (or maybe I screwed something up beyond fixing). I've been looking for fixes to no avail, I would greatly appreciate any help.

 

What I'm trying to do is create a tooltip that loads data via a MYSQL connection, displayed through PHP. I am using coolTips (JS) for the custom popup effect.

 

Here is my code for an anchor that opens the tooltip;

<?php 

$description = "<span class=\'ldescription\'>" . addslashes("$row[18]") . "</span>";

echo "
<a href=\"javascript:void(0);\" onclick=\"return coolTip('$description', WIDTH, 430, HEIGHT, 230, OTHER MISCELLANEOUS PARAMETERS); return true;\" onmouseout=\"nd(); return true;\">$row[1]</a>
";
?>

 

My problem occurs when there are double quotes (") in $description. Addslashes fixed the single quote (') problem, but when there are double quotes they end the anchor tag (it shows everything as a hyperlink from the end of $description to the beginning of the anchor closing tag).

 

Again, I'd greatly appreciate any help on this.

Link to comment
https://forums.phpfreaks.com/topic/84313-quote-woes-with-phpjs/
Share on other sites

It seems easier to troubleshoot this sans the whole database connection, variables,  etc...

 

<?php echo "
<a href=\"javascript:void(0);\" onclick=\"return coolTip('<div id=\'ctInside\'>SAMPLE TEXT</div>, SOME PARAMETERS'); return true;\" onmouseout=\"nd(); return true;\">link</a>
";

 

I just have some text (SAMPLE TEXT), inside an onclick (coolTip), inside an echo. How do I escape double quotes in this scenario? (If SAMPLE TEXT were SAM"PLE TEXT).

Link to comment
https://forums.phpfreaks.com/topic/84313-quote-woes-with-phpjs/#findComment-430391
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.