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

    Join Date
    Mar 2006
    Posts
    14
    Rep Power
    0

    HTML form and onlclick window.open


    Hi,

    I have a simple html form which when submitted I want to popup a new window which I can control the size of. Further, in the popup window I want to be able to access the form data.

    This is what I have done so far......

    Code:
    <form>
    <input type=text name=email size=27>
    <input class=button type="image" src="images/submit.jpg" onClick="window.open('send.php?subscribe=1', 'newWindow','width=300,height=150,'+'status=no,toolbar=no,menubar=no')">
    </form>


    When I submit the popup windows opens correctly and I am trying to access and output the two variables with php as follows:

    Code:
    $email = $_POST["email"]; 
    $subscribe = $_GET["subscribe"]; 
     
    echo $email $subscribe;


    Only the 'subscribe' variable which is passed in the url outputs correctly. [I]So my question is how do I accesss the variable input by the user into the form from the original page.[/I]

    Many thanks in advance.

    Rob.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Dec 2003
    Posts
    1,037
    Rep Power
    27
    1. Use the onsubmit event on the <form> instead of onclick on the <input>
    2. Set the target of the form to newWindow.
    3. Specify the method of the form to either GET or POST.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    14
    Rep Power
    0
    Thanks for the reply, this is what I have now:

    Code:
    <form method="POST" target="newWindow" onSubmit="window.open('send.php?subscribe=1', 'newWindow','width=300,height=150,'+'status=no,toolbar=no,menubar=no')">
                                    <input type=text name=email size=27>
    								<input class=button type="image" src="images/submit.jpg">
                                  </form>


    Then on the popup I have this:

    Code:
    $email = $_POST["email"]; 
    $subscribe = $_POST["subscribe"]; 
     
    echo $email $subscribe;


    However when I submit the form all that happens is the pop up open with the original page and not the intended popup.

    I am confused!

    Thanks,

    Rob.
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,131
    Rep Power
    4304
    You need to use the action attribute of form.

    Code:
    <form method="POST" action="send.php?subscribe=1" target="newWindow" onSubmit="window.open('', 'newWindow','width=300,height=150,'+'status=no,toolbar=no,menubar=no')">
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    14
    Rep Power
    0
    Thanks guys, you're stars but it does not take me to telll you that!

    I had been working on this for ages, all working great now.

    Many thanks!

    Rob.

IMN logo majestic logo threadwatch logo seochat tools logo