Who to escape special chars?

Discussion in 'JavaScript' started by Betty_S, Feb 4, 2007.

  1. #1
    Hi folks!

    My JS function takes the (text) value of a drop-down list and dynamecliy create a link which looks something like that:
    …?name=%D7%97%D7%99%D7%A4%D7%95%D7%A9+%D7%91…
    It works fine.
    Whoever if the passed text contains apostrophe, commas or hyphen it doesn't work because it will 'copy' the string until it hits those spcial chars.

    What to do!
     
    Betty_S, Feb 4, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    You can trey using the escape() function and then further special characters are encoded using a routine simmilar to:
    
    function encodeMyHtml() 
    {
         encodedHtml = escape(encodeHtml.htmlToEncode.value);
         encodedHtml = encodedHtml.replace(/\//g,"%2F");
         encodedHtml = encodedHtml.replace(/\?/g,"%3F");
         encodedHtml = encodedHtml.replace(/=/g,"%3D");
         encodedHtml = encodedHtml.replace(/&/g,"%26");
         encodedHtml = encodedHtml.replace(/@/g,"%40");
         encodeHtml.htmlEncoded.value = encodedHtml;
    }
    
    Code (markup):
    Although you can use the encodeURI() instead or escape() because "the escape and unescape functions do not work properly for non-ASCII characters and have been deprecated". That phrase is from: http://developer.mozilla.org/en/doc...fined_Functions:escape_and_unescape_Functions
     
    ajsa52, Feb 4, 2007 IP
  3. Betty_S

    Betty_S Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks :))
     
    Betty_S, Feb 5, 2007 IP
  4. Betty_S

    Betty_S Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    I need to replace the ' -' and ' " ' with something like %D4 or %F5 or whatever
    So can you tell me where I can find to full chars table?

    TKS,
     
    Betty_S, Feb 5, 2007 IP
  5. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #5
    ajsa52, Feb 5, 2007 IP