Click to See Complete Forum and Search --> : escape - or something like it


Webskater
09-09-2003, 10:51 AM
I am writing a recordset to the screen. Each row has a cell with a long description which I pass to a (vb) function to truncate. I also pass the string to a javascript function to display the (untruncated) string in a pop up window on mouseover.

If the string has an inverted comma in it - the javascript function fails.

I can loop through all the strings in vb and do a replace before it gets to the javascript function, but is there a better way? i.e. is there a javascript method that will go through the string and deal with offending characters - like escape does if you want to deal with offending characters before sending in a querystring. Thanks for any help.

requestcode
09-09-2003, 11:00 AM
You could escape the character so that JavaScript treats it as a normal character like this:
'Don\'t forget to escape the quote.'

You could also enclose a string with a single quote in double quotes like this:
"don't forget to escape the quote."

I think that is what you are looking for.

Webskater
09-09-2003, 11:45 AM
Thanks for your answer. I have done what you suggested already but it means I have to use the Replace function (vbscript) to loop through each string in each record and replace ' with \' but I also have double quotes and ampersands etc to deal with and it does not seem very efficient. I wondered if javascript has some way of doing this.