Jump to content


Passing variables to javascript

  • Please log in to reply
1 reply to this topic

#1 bcamp1973

  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 01 June 2006 - 06:54 PM

I want to pass variables (primarily text strings) to a couple javascript functions. However, there are several characters that javascript gets hung up on including parenthesis, commas, double and single quotes etc. What all do i need to escape beyond that? also, what's the best method for escaping these characters? str_replace() seems a bit cumbersome...is there something more efficient?

#2 poirot

  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 01 June 2006 - 07:19 PM

If the variables are text strings, enclose them in quotes (echo 'var = \'$variable\'';) and everything should be fine.

And you can also use addslashes() or htmlentities with ENT_QUOTES if you want to escape or convert quotes.
~ D Kuang

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users