Link to home
Start Free TrialLog in
Avatar of Stefan Motz
Stefan MotzFlag for United States of America

asked on

Recordset containing single quotes

Hi Experts,
I'm using a JavaScript to display a popup when I hover over a link.
Everything goes fine, except for records that contain single quotes.
e.g. if the last name is Smith, the code below will display "Smith" when I hover over the link:
<%=rs("Last_Name")%>
But if the last name is O'Brien, the popup won't appear.
I tried the following, without success:
<%=Server.HTMLEncode(rs("Last_Name").Value)%>

I would appreciate your help.
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Can you post the code for the link control ?
Avatar of Stefan Motz

ASKER

<a href="Edit.asp?Emp_Id=<%=rs("Emp_Id")%>" onmouseover="ddrivetip('<table width=400 bgcolor=#ffffff><tr><td style=\'border:1px solid #b0c4de;width:300px;\'>&nbsp;<%=rs("Last_Name")%> (<%=rs("Emp_Id")%>)&nbsp;</td></tr></table>', 'fffff0')" onmouseout="hideddrivetip()"><%=rs("Emp_Id")%></a>
I'm using the following method to display the link popup:

http://dynamicdrive.com/dynamicindex5/dhtmltooltip.htm
That site says:

One last important point: If your tooltip description contains apostrophes ('), be sure to backslash them first, as illustrated in the last example ("Yahoo\'s Site"), or an error will occur.

So at some point, you need to check Last_Name to see if it contains a quote.  I don't know how your records are bound to your controls, but one way to do this is in code behind before the data is bound to the control.  Use String.Replace()

s.Replace("'", @"\'");

On a side note, you might find a more modern solution using jQuery UI or Bootstrap Tooltip.
Avatar of Big Monty
you'll want to do a simple replace (or escaping) of the single quote:
<%=String( rs("Last_Name").Value ).replace( "'", "\'" )

 OR

<%=String( rs("Last_Name").Value ).replace( "'", "''" )

Open in new window

Hi Monty,
Thanks for your reply. It doesn't like the word String. This is the error I get:


Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'String'
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much both of you!
Monty's last suggested solution solved my problem.