We help IT Professionals succeed at work.

How to handle single quotation mark....

kgsoft_sys
kgsoft_sys asked
on
Dear experts..

i have a JSP page with the following code calling a JavaScript function...

<A href="javascript:checkPage('CH'NG BENG GUAN')">

it is a hyperlink...whenever i click this hyperlink..the Javascript will submit the form with the parameter to the Java Servlet to search for the details in hashtable based on this key:

CH'NG BENG GUAN

it is a person's name with a single quot mark (') in the third position..the problem is that JavaScript will give this as an error as this :

Line: 1
Cahr: 15
Error: expected ')'

so is there any special character we need to place together with the single quotation mark..so that Javascript can pass it to the function successfully...

it is quite urgent...pls give the solution asap..tq
Comment
Watch Question

Commented:
You can use a backslash to escape a quote inside quoute, like this: \'.

Commented:
Try escape.

<A href="javascript:checkPage(escape('CH'NG BENG GUAN'))">
How do you handle e.g. the next line:

document.writeln('<A href="javascript:checkPage('CH'NG BENG GUAN')">');

The string inside, which includes both single and double quote, comes from c-code and I cannot change it.

ahosangFinance Systems Developer

Commented:
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or so. I appreciate any comments that would help me to make a recommendation.
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
ahosang
ahosangFinance Systems Developer

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to alexcohn
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
Per recommendation, force-accepted.

Netminder
EE Admin

Explore More ContentExplore courses, solutions, and other research materials related to this topic.