Form to JavaScript.

Discussion in 'Javascript' started by Andrew Koptyaev, Feb 18, 2010.

  1. 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?
     
    Andrew Koptyaev, Feb 18, 2010
    #1
    1. Advertising

  2. Andrew Koptyaev

    rf Guest

    "Andrew Koptyaev" <> wrote in message
    news:hlit4m$72q$-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
     
    rf, Feb 18, 2010
    #2
    1. Advertising

  3. 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" <> Ñообщил(а) в новоÑÑ‚ÑÑ…
    Ñледующее:...
    > On 18/02/10 12:31, rf wrote:
    >> "Andrew Koptyaev" <> wrote in message
    >> news:hlit4m$72q$-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
     
    Andrew Koptyaev, Feb 18, 2010
    #3
  4. "Stefan Weiss" <> Ñообщил(а) в новоÑÑ‚ÑÑ…
    Ñледующее:...
    > 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?


    I just want to do modal window where I can make comment.
    For wordpress.
     
    Andrew Koptyaev, Feb 18, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Li Zhang
    Replies:
    4
    Views:
    6,087
    softip
    Feb 27, 2009
  2. Replies:
    7
    Views:
    634
  3. Replies:
    2
    Views:
    227
  4. rob c
    Replies:
    4
    Views:
    335
    McKirahan
    Dec 30, 2005
  5. Replies:
    5
    Views:
    196
Loading...

Share This Page