Forum Moderators: open

Message Too Old, No Replies

escaping quotes in document.write

         

sssweb

8:15 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



I have a document.write statement that includes a php string variable, and I'm getting errors whenever the php var happens to have a ' or " in it. Since I can't escape the quotes in that situation, is there another way to this? Here's my simplified code:

if ( document.all )
document.write('Text for IE4+ goes here {PHP_TEMPLATE_VAR} but php var w/quote causes error');

The text is longer than that, with more php vars, so I don't really want to string multiple js statements around the vars unless there's no other option.

eelixduppy

8:17 pm on Sep 18, 2006 (gmt 0)



You are going to want to use addslashes [us3.php.net] with the php variable before using it in the javascript.

Good luck

sssweb

9:14 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



ok - thanks.