Solved

Multiple layers of single quotes and Expected ')' error

Posted on 2006-07-11
3
230 Views
Last Modified: 2006-11-18
I am trying to build an HTML string on the client side, using data passed from a database query on the server side.  Here is a sample of what I'm doing:

strNotes = arrRow[5];
strNotes = replaceString(strNotes, "'", "\'");

strOnMouseOver = 'ddrivetip(\'Notes: ' + strNotes + '\', 150);changeStyleRow(' + i + ', \'checkbook_entry_over\');';

objString.append('<TD ID="date_' + i + '" CLASS="checkbook_entry_gray" ONMOUSEOVER="' + strOnMouseOver + '" ONMOUSEOUT="' + strOnMouseOut + '" ONCLICK="' + strOnClick + '">' + strDate + '</TD>');

This code works just fine, unless arrRow[5] contains an apostrophe.  If it does contain one, I get the Expected ')' error.  Also, if I change this:
strNotes = replaceString(strNotes, "'", "\'");

to something like this:
strNotes = replaceString(strNotes, "'", "XXX");

The code works fine.

What am I missing?

jmanGJHS97
0
Comment
Question by:jmanGJHS97
3 Comments
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 17081749
Try this one.

strNotes = escape(arrRow[5]);
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 17081765
does this work?

strNotes = replaceString(strNotes, "'", "\\'");
0
 
LVL 9

Author Comment

by:jmanGJHS97
ID: 17081815
pravinasar,

I had thought of that too, but that just puts %27, etc in the string.  So that's not going to do.

knightEknight,

That worked like a charm.  Thanks very much.  I had tried "\'\'" previously, but to no avail.  Thanks for your help.

jmanGJHS97
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now