#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Berlin
    Posts
    11
    Rep Power
    0
    Hi!

    I've got the following problem:

    I built a page where the user can give a few variables via simple HTML-inputs and then - after it's from this specifications (e.g. target address) a JavaScript shall generate the PHP code for this problem and put in in a <textarea>

    BUT: I can't tell my JS function to write the PHP-begin and end-tags ("<?php" and "?>"), because this script is placed in a .php file and when the parser sees this <?php it thinks now it shall interprete the following code.

    Example:

    document.form.generated_code.value = "<?php echo('Hello " + document.form.text + "! ') ?>";

    So:

    How can my JS script generate PHP code???

    Thanks!

    Filip
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Brisbane, Australia
    Posts
    32
    Rep Power
    14
    Try replacing the

    <?php

    with

    &lt;?php

    and the

    ?>

    with

    ?&gt;

    in your javascript.

    That should work.

    Regards,
    Robbo
    Last edited by R0bb02001; April 29th, 2001 at 05:44 AM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Amsterdam/Cologne
    Posts
    2
    Rep Power
    0

    Cool


    Hey,

    since PHP is a server side parsed and JavaScript a client side parsed language I don't think that you can create php code with javascript - that would mean that the browser has to parse the php which does not work.
    If you just wanna print a form value use the javascript document.write('') or document.writeln('')...
    Hope I am right
    Greetingz,

    nikolai
    Last edited by Nikjazz; April 29th, 2001 at 06:15 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Brisbane, Australia
    Posts
    32
    Rep Power
    14
    From what Filip explained I thought that he was saying (I may be wrong) that the php code is not parsed, its just put into a textarea box in a form, which then the user can copy or whatever...

    You would be right in that JavaScript cannot create PHP code to be parsed Nikolai, but I don't think that this is what Filip is looking for.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Berlin
    Posts
    11
    Rep Power
    0
    Hi!

    Sorry, if this wasn't clear (my english...)

    The script only should be create the PHP code and put in this <textarea>, the code should not be executed after it was generated, only the user can copy the code and put in in his files.

    @R0bb...: I just tried it with &lt; and &gt; but then the JS script inserts really "&lt;" and "&gt;" in the <textarea>, not the wanted "<" and ">".
    But thanks anyways!


    Filip
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Berlin
    Posts
    11
    Rep Power
    0
    Hey!

    This is really paralled work! We are just two different processes.... ;-)
  12. #7
  13. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    England, UK
    Posts
    83
    Rep Power
    15
    You could split the tags:

    Code:
    document.form.generated_code.value = "<" + "?php echo('Hello " + document.form.text + "! ') ?" + ">";
    Girish Gupta
    girish@musicgoeson.com

    MSN Messenger: girish@musicgoeson.com
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Amsterdam/Cologne
    Posts
    2
    Rep Power
    0
    yeah this should work - but the "&lt;" thing should work to - did ya put it into "&lt;" ? not '&lt;' I am not really shure now since i didn't try it - but who knows...
    greetz,

    nikolai
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Berlin
    Posts
    11
    Rep Power
    0
    Thanks girish_gupta!!!
    This really does it!

    A really easy solution!


    Filip
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Brisbane, Australia
    Posts
    32
    Rep Power
    14
    Nah Nikolai, I was thinking it was about 50-50 as to wether using &gt; etc. would work because a textarea form is not parsed by your browser.

    I mean, the &gt; is parsed by the browser and converted into > when it sees it in PHP, but a form box is not processed as HTML.

    The more I think about it, the more stupid I feel for thinking that it may work

IMN logo majestic logo threadwatch logo seochat tools logo