#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Philadelphia
    Posts
    239
    Rep Power
    14

    Generating Javascript


    I don't know much about javascript, but I was able generate some javascript from some data retrieved from my database:

    echo "document.write(\";
    // echo my data...
    echo "\");

    this works fine.

    but i'm having trouble generating a form this way:

    echo "document.write(\";
    echo "<FORM ACTION=\"http://www.mysite.com/process.php?\" METHOD=\"post\">";
    //rest of form...
    echo "</FORM>";
    echo "\");

    Is there a certian way you need to refer to form elements or form tags. I tried stripping echoed lines out one by one and it seems to be choking on the form tags.
  2. #2
  3. No Profile Picture
    PHP Coder
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Ontario
    Posts
    66
    Rep Power
    14
    echo can be broken across multiple lines...

    echo "
    <script>
    <!--
    document.write('<form action=\"http://www.mysite.com/process.php?\" method=\"post\"><!-- rest of form... --></form>');
    // -->
    </script>
    ";

    document.write, on the other hand, is restricted to one line.
    Click here and wait. It's a kewl effect, trust me.
  4. #3
  5. funky munky
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2001
    Location
    UK
    Posts
    1,446
    Rep Power
    16
    ahhh

    so you could do:
    PHP Code:
    $jsString="document.write(\""
            
    ."<FORM ACTION=\"http://www.mysite.com/process.php?\" METHOD=\"post\">"
            
    ."rest of form...".
            .
    "</FORM>"
    maybe and then echo or print the $jsString out:

    PHP Code:
    print($jsString); 
    ???
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Philadelphia
    Posts
    239
    Rep Power
    14
    ok. but if i'm echoing my form between the document.write statement

    echo "document.write(\";
    // echo my form data...
    echo "\");

    isn't that generating one line.
  8. #5
  9. funky munky
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2001
    Location
    UK
    Posts
    1,446
    Rep Power
    16
    I don't echo at all really... always use print() so I'm not sure ;(

    time for http://php.net/echo ...

    mmm, reading between the lines (geddit, *groan*) the echo *construct* outputs newlines implicitly, whereas with the print() *function* newlines must be added explicitly.

IMN logo majestic logo threadwatch logo seochat tools logo