Fuego
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?
So How can I escape the ' character
ex. When its filled in @ a form?
|
||||
escaping 'Fuego 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? glenngv 04-27-2004, 10:24 AM You escape a character by using backslash before the character \' Fuego 04-27-2004, 10:32 AM But when I use that at my Replace function String.prototype.repAp=function(){ return this.replace(/'/g,"\'"); } It still doesnt work glenngv 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. Fuego 04-27-2004, 11:52 AM Well eval("document.formulier.str1" + i + ".value='" + eval("document.formulier.str1" + i + ".value.toLowerCase().repAp;") + "'"); and my function String.prototype.repAp=function(){ return this.replace(/'/g,"\\'"); } glenngv 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