View Full Version : escaping '

04-27-2004, 09:49 AM
My Javascript wont run when I fill '
So How can I escape the ' character
ex. When its filled in @ a form?

04-27-2004, 10:24 AM
You escape a character by using backslash before the character


04-27-2004, 10:32 AM
But when I use that at my Replace function

return this.replace(/'/g,"\'");

It still doesnt work

04-27-2004, 11:11 AM
You are in effect replacing ' with the same '
I don't know why do you want to change it but try this:

return this.replace(/'/g,"\\'");

That will insert a "literal" backslash inside the original string. I don't know if that's what you want.

var str="I'm happy";
str = str.repAp();
alert(str); //alerts I\'m happy

Can you elaborate more on this, I'm curious why do you want to do that.

04-27-2004, 11:52 AM

eval("document.formulier.str1" + i + ".value='" + eval("document.formulier.str1" + i + ".value.toLowerCase().repAp;") + "'");

and my function

return this.replace(/'/g,"\\'");

04-27-2004, 11:58 AM
You're having trouble with single quotes because you are using eval which should not be used in the first place.

document.formulier.elements["str1" + i].value=document.formulier.elements["str1" + i].value.toLowerCase();

You should definitely learn javascript bracket notation (http://www.litotes.demon.co.uk/js_info/sq_brackets.html).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum