Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    echo Auto Execute

    Hello,

    I’m not sure which this will end up being – a PHP or a JavaScript question.

    I have a form that, after submitting it, a link appears in the echo with an onClick that when clicked opens a window. I am wondering how to make this action (the onClick) automatic so that when the form is submitted the echo automatically opens the window.

    I have attached a simple example of my current form.

    Thank you for any help in advance.
    Attached Files Attached Files

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd probably run my body tag through an if statement: If your form's been submitted, have it put an onLoad in the tag.

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the response.

    I'm not sure how to implement that. Your assistance would be greatly appreciated.

  • #4
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    if( $_POST['yoursubmit'] )
    {
      echo 
    '<body onLoad="yourFunction()">';
    }
    else
    {
      echo 
    '<body>';

    I may have the onLoad syntax off; you may want to double-check it.

    [Edit] I'm pretty sure the onLoad won't go into affect until after the entire page has been served up, so it shouldn't interfere with any processing. I've never tried it, though, so you may want to run a couple of tests...
    Last edited by Kid Charming; 06-07-2005 at 03:31 AM.

  • #5
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I spent awhile attempting to implement your suggestion. Unfortunately I have not yet been successful. I do have a couple questions. In the end, will the body tag in the echo interfere with the body tag at the top of the html? Second, what value should I be putting where 'yoursubmit' is?

    Thanks again.

  • #6
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    PHP Code:
     if( $_POST['yoursubmit'] ) 
    yoursubmit would be changed to the name of your submit button. By default the name of it should be Submit so you would use.

    PHP Code:
     if( $_POST['Submit'] ) 
    just be carefull of case sensitive names and make sure they match. also the <body> tags that are echo'd should not be rendered to the browser as long as you have it placed in the right spot you should be fine.

    i.e

    PHP Code:
    <html>
    <head>
    <script>
    function test()
    {
      alert('lah lah lah');
    }
    </script>
    </head>
    <?
    if( !isset($testing) )
    {
      echo 
    '<body onLoad="test()">';
    }
    else
    {
      echo 
    '<body>';
    }
    ?>
    Body of your page here
    </body>
    </html>

  • #7
    New Coder
    Join Date
    Jun 2004
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much Kid Charming and Serex!

    It works beautifully. I found (as Serex said) that the PHP code needs to be placed above the body tag of the html. Then when the form is submitted the body tag in the echo sort of "overrides" the existing body tag.

    Thanks again!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •