Solved

Multiple layers of single quotes and Expected ')' error

Posted on 2006-07-11
3
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

724 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