• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Multiple layers of single quotes and Expected ')' error

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?

1 Solution
Pravin AsarPrincipal Systems EngineerCommented:
Try this one.

strNotes = escape(arrRow[5]);
does this work?

strNotes = replaceString(strNotes, "'", "\\'");
jmanGJHS97Author Commented:

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


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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now