From: Andrew Koptyaev on 18 Feb 2010 03:18 Hello I have Facebox javascript to output anything in modal window. I want to display at modal box a form. Form - it is html code. The form I do generate in the php code - for now just echo all elements to buffer and then put buffer to variable. I have a question - what way I can pass this variable with form to script? Or may be other solution to pass from php to javascript a form?
From: rf on 18 Feb 2010 06:31 "Andrew Koptyaev" <hazehog(a)gmail.com> wrote in message news:hlit4m$72q$1(a)news.eternal-september.org... > Hello > > I have Facebox javascript to output anything in modal window. > I want to display at modal box a form. Form - it is html code. > The form I do generate in the php code - for now just echo > all elements to buffer and then put buffer to variable. > I have a question - what way I can pass this variable with > form to script? > Or may be other solution to pass from php to javascript > a form? 42
From: Stefan Weiss on 18 Feb 2010 07:49 On 18/02/10 12:31, rf wrote: > "Andrew Koptyaev" <hazehog(a)gmail.com> wrote in message > news:hlit4m$72q$1(a)news.eternal-september.org... >> Hello >> >> I have Facebox javascript to output anything in modal window. >> I want to display at modal box a form. Form - it is html code. >> The form I do generate in the php code - for now just echo >> all elements to buffer and then put buffer to variable. >> I have a question - what way I can pass this variable with >> form to script? >> Or may be other solution to pass from php to javascript >> a form? > > 42 Heh. I was thinking the same thing when I read the question :) OP, it's hard to understand what you're trying to do ("Facebox javascript to output anything in modal window" doesn't mean anything at all to me). Are you trying to set the value of a JS variable from PHP? If so, all you need is <script type="text/javascript"> var myHtmlString = "<?= escapeJS($htmlString) ?>"; </script> You'll have to provide an "escapeJS" function; maybe something like this: function escapeJS ($str) { $str = strtr($str, array( "\b" => '\b', "\f" => '\f', "\n" => '\n', "\r" => '\r', "\t" => '\t', "'" => "\\'", '"' => '\\"', "\\" => "\\\\", )); return str_replace("</", "<\\/", $str); } If you're using XHTML, you'll also need to escape the XML special characters, or use a CDATA block. Another possibility would be to fetch the HTML content with an XMLHttpRequest. If that doesn't answer your question, you'll need to provide some details. In the meantime, I'm sure somebody will find a problem with my escapeJS() example, and we'll have a nice discussion about that ;-) -- stefan
From: Andrew Koptyaev on 18 Feb 2010 08:34 I have html in the PHP variable like: $face_form = '<h3>Leave a Reply</h3><div class="cancel-comment-reply">'; I want pass this variable by onclick to javascript. Like: echo '<a href="#modalcomment" onlick="modalcommenttask(' . $face_form . ');">' . 'TEXT' . '</a>'; But I can't pass variable since it have double quotes: onlick="modalcommenttask(h3>Leave a Reply</h3><div class=" What the solution to pass html form from PHP to javascript function. "Stefan Weiss" <krewecherl(a)gmail.com> сообщил(а) в новостях следующее:XL6dnT-F1-DbquDWnZ2dnUVZ8n6dnZ2d(a)giganews.com... > On 18/02/10 12:31, rf wrote: >> "Andrew Koptyaev" <hazehog(a)gmail.com> wrote in message >> news:hlit4m$72q$1(a)news.eternal-september.org... >>> Hello >>> >>> I have Facebox javascript to output anything in modal window. >>> I want to display at modal box a form. Form - it is html code. >>> The form I do generate in the php code - for now just echo >>> all elements to buffer and then put buffer to variable. >>> I have a question - what way I can pass this variable with >>> form to script? >>> Or may be other solution to pass from php to javascript >>> a form? >> >> 42 > > Heh. I was thinking the same thing when I read the question :) > > OP, it's hard to understand what you're trying to do ("Facebox > javascript to output anything in modal window" doesn't mean anything at > all to me). Are you trying to set the value of a JS variable from PHP? > If so, all you need is > > <script type="text/javascript"> > var myHtmlString = "<?= escapeJS($htmlString) ?>"; > </script> > > You'll have to provide an "escapeJS" function; maybe something like this: > > function escapeJS ($str) > { > $str = strtr($str, array( > "\b" => '\b', > "\f" => '\f', > "\n" => '\n', > "\r" => '\r', > "\t" => '\t', > "'" => "\\'", > '"' => '\\"', > "\\" => "\\\\", > )); > return str_replace("</", "<\\/", $str); > } > > If you're using XHTML, you'll also need to escape the XML special > characters, or use a CDATA block. > > Another possibility would be to fetch the HTML content with an > XMLHttpRequest. > > If that doesn't answer your question, you'll need to provide some > details. In the meantime, I'm sure somebody will find a problem with my > escapeJS() example, and we'll have a nice discussion about that ;-) > > > -- > stefan
From: Stefan Weiss on 18 Feb 2010 09:00 On 18/02/10 14:34, Andrew Koptyaev wrote: > I have html in the PHP variable like: > $face_form = '<h3>Leave a Reply</h3><div class="cancel-comment-reply">'; > > I want pass this variable by onclick to javascript. Like: > echo '<a href="#modalcomment" onlick="modalcommenttask(' . $face_form . > ');">' . 'TEXT' . '</a>'; > > But I can't pass variable since it have double quotes: > onlick="modalcommenttask(h3>Leave a Reply</h3><div class=" > > What the solution to pass html form from PHP to javascript function. But... I just explained how! You need to escape the string contents, and you (obviously) need to wrap the string in quotes (double or single), like you do in PHP. Since you're putting all of this inside an HTML attribute, so you'll have to escape the HTML special characters as well (including quotes). The htmlspecialchars() function does that for you. Anyway, having escaped HTML in an HTML attribute... brrr. Are you sure this is the best way to do it? (and please don't top-post on Usenet) -- stefan
|
Next
|
Last
Pages: 1 2 Prev: Capture browser refresh using OnBeforeUnload event Next: A good opportunity to investment |