Output Within Javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Output Within Javascript

Post 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.
Last edited by icesolid on Thu Jan 25, 2007 12:57 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

FYI, Java and Javascript are two completely seperate entities.

Moved to Client-Side.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

I understand that, I am sorry. No help though?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Hrm, I'm kind of coming to a blank here. Try changing the \" to the quotes html entity, being: "
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post 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>";
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

replace addslashes with htmlentities(), or htmlspecialchars()
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

That solved most of the problems other than now any string that contains a ' doesent work
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

doesn't work? explain
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Code: Select all

str_replace("'","\'",htmlentities($row["note"]))
?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I forgot to mention, use

Code: Select all

htmlentities($row['note'], ENT_QUOTES)
to fix the single quote issue
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post 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>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Did you try my last suggestion?
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

Yes, it worked. Thank you sir!
Post Reply