Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:07

ToolTip Text: Single Quotes Should Be Replaced By '


Poster: Bob Martin
Dated: Monday October 4 2004 - 21:26:32 BST

Some text which I have been using for tool tip text (from an external database) using onfunction=showtip() has single quotes it in, which in turn causes a Javascript error within the Milonic runtime when the mouse hovers above that menu item.

My workaround, which I think should be part of your menu item build process, should be to replace any single quotes with the HTML equivalent, as in :

Code:
tooltip.replace(/'/g, "&#xx;"); <!-- where xx is 39 for a single quote -->


Thoughts?

Thanks in advance,

Bob Martin


Poster: kevin3442
Dated: Tuesday October 5 2004 - 6:26:46 BST

The problem will occur if you pass a literal string to the showTip() function using single quotes around the string (showTip('like thisexample') ). In that case, the additional apostrophe in the string is interpreted as the end of the string, and then there's a bunch of other stuff folowing it that doesn't beong there. It gets harrier if you're passing it in a js call in the url attribute of a static link <a url="javascript:showTip('like ths example')">click me</a>, because people will ften enclose the url argument in double quotes, leaving single qutesas the only thing left in the call to showTip().

I'm rambling.... it's late.

Anyway.. this is a general problem with string handling in js, not something specific to the menu or to the tooltips add-on. Your suggestion of using an html code is a good one. I find that another approach would be to escape the single quote so that it is interpreted literally, as part of the string. "Escaping a quote" is accomplished by placing a backslash in front of it, like so: \'.
Code:
showTip('A single quote as an apostrophes shouldn\'t be a problem here, because it\'s escaped.')


Cheers,

Kevin


Poster: perldev
Dated: Tuesday October 5 2004 - 17:02:22 BST

If you use perl, you have to escape \ first. For an example:

Code:
print <<EOF;
<a href="showTip('This is perldev\\'s test.')">whatever</a>
EOF