Jump to content

Archived

This topic is now archived and is closed to further replies.

bcamp1973

Passing variables to javascript

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.