Click to See Complete Forum and Search --> : Javascript Escaping


alan89
04-05-2009, 04:39 PM
Hi,

I am having a problem with users entering characters such as ' and " into a form which javascript then sends the variables via ajax to the server.

The user is trying to enter, example:
Hello, <a href='http://www.mydomain.com'>thisisalink</a>

With that is entered it returns an error:

malformed URI sequence
if (value != undefined) value = decodeURIComponent(value);
(This is from prototype.js)

However, if I take the text and re-type the ' and " manually they submit fine without any encoding errors.

I've tried; escape, encodeURI and encodeURIComponent and still no success.

What Javascript encoding should I be using?

Thanks!

Krik
04-06-2009, 12:31 AM
you could try using "replace"


data.replace(/\"/gm, "&quot");
data.replace(/\'/gm, "'");

My regular expressions knowledge is weak but I am sure you can find a hundred examples of how to replace the single and double quotes with a google search.