How do I escape data in javascript?

Discussion in 'JavaScript' started by Imozeb, Jun 28, 2010.

  1. #1
    I am getting data through php via <a onmouseup="fnc('needs_to_be_escaped_var')"></a>

    I've been trying to escape it in php but it isn't working. I was wondering if there was a way to escape it in javascript? Thanks.

    (I need to escape out single and double quotes for outputing into an html div)
     
    Imozeb, Jun 28, 2010 IP
  2. siothach

    siothach Active Member

    Messages:
    656
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #2
    easiest way: use escape(charstring) method, or encodeURI( URIString ) or encodeURIComponent( encodedURIString )
     
    siothach, Jun 28, 2010 IP
  3. GFX_Lover

    GFX_Lover Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Use this:
    escape();
     
    GFX_Lover, Jun 29, 2010 IP
  4. anands

    anands Well-Known Member

    Messages:
    436
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    120
    #4
    anands, Jul 1, 2010 IP