Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

how can I pass a string with apostrophe

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

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

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

I suggest you use double quotes:


onClick="return SendValue(\"#UrlVal#\");">
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?
using double quotes will not help if the value contains double quotes...
Avatar of lulu50

ASKER

I tried double quotes and that did not work

the value coming from the database
Avatar of lulu50

ASKER

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
Avatar of lulu50

ASKER

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#
Avatar of lulu50

ASKER

#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 \
Avatar of lulu50

ASKER

oh I got it
Avatar of lulu50

ASKER

Thank you Guy for telling that I have to put \  when I did it works fine


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

ASKER

Thank you all for your help