Help me to fix this little javascript problem.

Discussion in 'JavaScript' started by bobbyr, Jun 18, 2007.

  1. #1
    Hi Guys

    I have this string <a href=javascript:// onClick="changeImageInfo('$listing_url$/images/$file$','$desc$');return false;">
    <img src="$listing_url$/images/$thumbnail$"> and when someone add a ' or '' in the description who is describe as $desc$ I have a javascript error. How can I escape the strings, so ' and " become \' and \" .

    Bobby
     
    bobbyr, Jun 18, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  3. bobbyr

    bobbyr Peon

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi nico

    Thanks for your answer but the page is not a php so I can't use it. Anybody else with another solution please?
     
    bobbyr, Jun 19, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I thought these were PHP variables.

    Where does $desc$ come from then? And what is it? Once the Javascript is outputted wrong, there's no way to fix it later. You have to make sure these replacements take place before they're outputted.
     
    nico_swd, Jun 19, 2007 IP
  5. bobbyr

    bobbyr Peon

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi bro thanks for your answer.

    $desc$ is a term in a perl script to show the description that someone give to a picture. Maybe that I need to change it directly in the perl script itself?

    If so are you looking for a small job like that if you know perl language?

    Let me know
    Bobby
     
    bobbyr, Jun 19, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Sorry, I don't know anything about Perl.

    But yes, you will have to apply a function to the variable before outputting it.
     
    nico_swd, Jun 19, 2007 IP
  7. bobbyr

    bobbyr Peon

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok thanks nico do you know any good perl programmer?
     
    bobbyr, Jun 19, 2007 IP