/    Sign up×
Community /Pin to ProfileBookmark

Passing a single quote

I’m getting an error message when I attempt to pass a string variable with an apostrophe in it, to a Javascript function. The apostrphe is inside a string variable retrieved from an Oracle database. How can I pass a string variable with an apostrophe in it to a javascript function?

Example:

<cfset comments = ‘It’s a problem’

<a class=myMenu href=”javascript:submitform( ‘#comments#’)”>#comments#</a>

function submitform(comments)

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@felgallOct 30.2006 — Three solutions:

comments = "It's a problem"

comments = 'It's a problem'

comments = 'It&apos;s a problem'
Copy linkTweet thisAlerts:
@DDANIEL11authorOct 30.2006 — I gave you a bad example. The variable is coming from an Oracle database. I have no control over it and the position of the apostrophe in it.
Copy linkTweet thisAlerts:
@slaughtersOct 30.2006 — Encode it with a serverside HTML Encode command (URLEncoder for Java/JSP) after getting it from the database, but prior to passing it to your page.

OR

Do a simple string replace on the server side using Regular expressions to replace the single tic mark with one of the three replacements mentioned by felgall

[edit]

For ColdFusion use [URL=http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/funca114.htm]URLEncodedFormat[/URL]

[/edit]
Copy linkTweet thisAlerts:
@vladiboOct 30.2006 — I think this is rather ColdFusion than JavaScript question. You can encode it on the server side as it was suggested in the previous answer
×

Success!

Help @DDANIEL11 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...