Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: escaping '

  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    escaping '

    My Javascript wont run when I fill '
    So How can I escape the ' character
    ex. When its filled in @ a form?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You escape a character by using backslash before the character

    \'
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But when I use that at my Replace function
    Code:
    String.prototype.repAp=function(){
       return this.replace(/'/g,"\'");
    }
    It still doesnt work

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Last edited by glenngv; 04-27-2004 at 12:15 PM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Mar 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well

    Code:
    eval("document.formulier.str1" + i + ".value='" +  eval("document.formulier.str1" + i + ".value.toLowerCase().repAp;") + "'");
    and my function
    Code:
    String.prototype.repAp=function(){
       return this.replace(/'/g,"\\'");
    }

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •