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
Share on other sites

Thanks for the reply, but it did not work.

 

The $row[18] variable is a varchar which is loading from a database. When this string of text has quotes (Here's an "example.") it does what I described in the original post.

 

 

Link to comment
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
Share on other sites

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.