Page 1 of 1

Output Within Javascript

Posted: Thu Jan 25, 2007 12:33 pm
by icesolid
I have a string of text print out into a tooltip window.

My problem is that if there are any quotes in the string the tooltip will not show.

Here is the output that doesent work because of the quotes in the output (I have addslahes(); on the string).

Code: Select all

<a href="#" onMouseover="fixedtooltip('Source at contact number said that \"this week is no good\" on our first trip to the area.  We will try again.', this, event, '300px')" onMouseout="delayhidetip()"><img src="../img/note.gif" border="0"></a>
Anyways to escape this? addslashes() does not work either.

Posted: Thu Jan 25, 2007 12:38 pm
by John Cartwright
FYI, Java and Javascript are two completely seperate entities.

Moved to Client-Side.

Posted: Thu Jan 25, 2007 12:43 pm
by icesolid
I understand that, I am sorry. No help though?

Posted: Thu Jan 25, 2007 12:48 pm
by John Cartwright
Hrm, I'm kind of coming to a blank here. Try changing the \" to the quotes html entity, being: "

Posted: Thu Jan 25, 2007 12:49 pm
by icesolid
These are dynamically printed out. Here is the PHP code producing the result above:

Code: Select all

echo "<a href=\"#\" onMouseover=\"fixedtooltip('" . addslashes($row["note"]) . "', this, event, '300px')\" onMouseout=\"delayhidetip()\"><img src=\"../img/note.gif\" border=\"0\"></a>";

Posted: Thu Jan 25, 2007 12:57 pm
by John Cartwright
replace addslashes with htmlentities(), or htmlspecialchars()

Posted: Thu Jan 25, 2007 1:01 pm
by icesolid
That solved most of the problems other than now any string that contains a ' doesent work

Posted: Thu Jan 25, 2007 1:02 pm
by John Cartwright
doesn't work? explain

Posted: Thu Jan 25, 2007 1:04 pm
by Kieran Huggins

Code: Select all

str_replace("'","\'",htmlentities($row["note"]))
?

Posted: Thu Jan 25, 2007 1:05 pm
by John Cartwright
I forgot to mention, use

Code: Select all

htmlentities($row['note'], ENT_QUOTES)
to fix the single quote issue

Posted: Thu Jan 25, 2007 1:07 pm
by icesolid
These two outputs give me errors now:

Code: Select all

<a href="#" onMouseover="fixedtooltip('1st trip wk of 1-22 he said he would not cooperate until he got a "letter from Farmer's"!  We called agent and Shannon got him to be more cooperative.  We will try again next trip.  ', this, event, '300px')" onMouseout="delayhidetip()"><img src="../img/note.gif" border="0"></a>

Code: Select all

<a href="#" onMouseover="fixedtooltip('On first trip we arrived and no one there.  We called and left message-no response.   Next day we called and he said he WAS there, but didn't hear us knocking and didn't get our message.  Will try agn', this, event, '300px')" onMouseout="delayhidetip()"><img src="../img/note.gif" border="0"></a>

Posted: Thu Jan 25, 2007 1:09 pm
by John Cartwright
Did you try my last suggestion?

Posted: Thu Jan 25, 2007 1:11 pm
by icesolid
Yes, it worked. Thank you sir!