Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Single and double quote problem

Thread Tools

Single and double quote problem
Posts: n/a
Hi All-

I'm pretty sure this have been discussed earlier, but couldn't find a
solution to my problem.

<input type="submit"
value="Delete Parts"
onclick="return handleDeleteParts('ABC', 'MY

I'm using something (Struts ResponseUtils.filter()) which translate 'MY
DESCRIPTION' in such a manner that a double quote is replaced by &quot;
and a single quote to '

The problem is if there is a single quote (translated to ') i get a
javascript error (small error icon on the status bar)it says, "Error:
Expected ")"

if I change the above to:

<input type="submit"
value="Delete Parts"
onclick='return handleDeleteParts("ABC", "MY

it works fine, but a new error is introduced in that now i run into the
same problem is MY DESCRIPTION has a double quote in it.

Here is an actual line:

<input type="submit"
value="Delete Parts"

onclick="return handleDeleteParts('XF2',
''Mustang' Logo Fabric Bucket Seats')">

Any help is appreciated.

Reply With Quote
Posts: n/a
Use String.fromCharCode(i) to replace the single and double quotes.

For example, if your string is O'douls, and you want it enclosed in
single quotes, replace the single quote with:


So an example line might look like:

fromCharCode documentation at MSDN:

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with single-quote and double-quote when using subprocess. Evan Python 3 11-04-2008 12:24 PM
problem with quote and single-quote when using "subprocess" Evan Python 1 11-04-2008 12:08 AM
How to handling string contains single quote and double quote vikrant Perl Misc 8 05-17-2007 04:37 PM
Datagrid on load; replace all double single quote to single quote to display to user Eric Layman ASP .Net 3 04-14-2007 07:16 AM
Single Quote Versus Double Quote In A href link HTML 3 06-13-2006 12:42 AM