Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Single and double quote problem

 
 
davegraham_1998@yahoo.com
Guest
Posts: n/a
 
      03-23-2005
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
DESCRIPTION')">

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
DESCRIPTION")'>

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"
DISABLED
value="Delete Parts"

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

Any help is appreciated.

 
Reply With Quote
 
 
 
 
humbads
Guest
Posts: n/a
 
      03-25-2005
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:

'+String.fromCharCode(39)+'

So an example line might look like:
alert('O'+String.fromCharCode(39)+'douls');

fromCharCode documentation at MSDN:
http://tinyurl.com/6o3x6

 
Reply With Quote
 
 
 
Reply

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 knee-dragger@hotmail.com HTML 3 06-13-2006 12:42 AM



Advertisments