Single and double quote problem

D

davegraham_1998

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.
 
H

humbads

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,255
Members
46,856
Latest member
MyronKatz6

Latest Threads

Top