Click to See Complete Forum and Search --> : coding for the quote symbol in javascript


spacesaver
12-02-2003, 08:35 AM
hi. I'm trying to write a javascript function that will display a string to a textbox on my html page. However, I'd like the string to contain a quote symbol. Can anyone tell me how to do this?

requestcode
12-02-2003, 08:42 AM
You can "escape" the symbol so it is treated as normal text like this: "I\'d like the string to contain a quote symbol".
Notice the "\" in front of the quote? The same would work if you want to use a double quote in a string.

spacesaver
12-02-2003, 08:48 AM
requestcode:
Thanks so much!

ccoder
12-02-2003, 10:44 AM
You should also be able to enclose the string with the quote symbol that you are not embedding.

Anyway, the following should all work in IE and NN:

"I'd like the string to contain a quote symbol"
"I\'d like the string to contain a quote symbol"
'I\'d like the string to contain a quote symbol'
'As I said "The above should all work"'

I'm not sure about the other browsers out there.