Solved

how can I pass a string with apostrophe

Posted on 2015-01-30
12
157 Views
Last Modified: 2015-01-30
Hi,

I need your help please, I have an onclick event that I am passing a variable.

the value of that variable has apostrophe. How can I pass my value with apostrophe in it?

here's what I have

the value for "cn" is = 'O'brianes'

onClick="return SendValue('#UrlVal#');">

so this is how it looks

onClick="return SendValue('O'brianes');">

How can I fix this issue? 

Please help thank you 

Open in new window

0
Comment
Question by:lulu50
  • 8
  • 3
12 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
you have to escape it:

onClick="return SendValue('O\'brianes');">

using escape or encoreURI
http://www.w3schools.com/jsref/jsref_escape.asp


onClick="return SendValue(escape('#UrlVal#') );">
0
 

Author Comment

by:lulu50
Comment Utility
Guy,



I changed the code to this: 
onClick="return SendValue(escape('#GetSomeUsers.cn#')">


My output now is this: 
return SendValue(escape('O'Brien, Smith'));

Open in new window

0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
Comment Utility
I suggest you use double quotes:


onClick="return SendValue(\"#UrlVal#\");">
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
looks like I confused the "html/url" part ...

you may want to try eval...
onClick="return SendValue(eval('GetSomeUsers.cn') )">

anyhow, where does the value come from?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
using double quotes will not help if the value contains double quotes...
0
 

Author Comment

by:lulu50
Comment Utility
I tried double quotes and that did not work

the value coming from the database
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:lulu50
Comment Utility
How can I in Javascript
make this value :
onClick="return SendValue('#GetSomeUsers.cn#' )"

turn to this value:

O\'brianes

if I replace '  with \'  then it will work (How can I do the replace in javascript)

onClick="return SendValue('#GetSomeUsers.cn#.replace(/'/g, "")' )"

something like the above syntax
0
 

Author Comment

by:lulu50
Comment Utility
if I do this then it works

onClick="return SendValue('O\'brianes')

so I need to replace '    with    \'   in order to work with my passed variable #GetSomeUsers.cn#
0
 

Author Comment

by:lulu50
Comment Utility
#REReplace(GetSomeUsers.cn,"''","'","ALL")#

but I need to add the \  to get to this result   O\'brianes  I don't know where to put the \
0
 

Author Comment

by:lulu50
Comment Utility
oh I got it
0
 

Author Comment

by:lulu50
Comment Utility
Thank you Guy for telling that I have to put \  when I did it works fine


onClick="return SendValue('#REreplace(GetSomeUsers.cn, "'", "\'", "all")#')
0
 

Author Closing Comment

by:lulu50
Comment Utility
Thank you all for your help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now