Results 1 to 6 of 6

Thread: New Window Open on post data

  1. #1
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default New Window Open on post data

    When i press button i would like to post data and open posted data in new window. Here is my code

    onclick="
    window.open('new.html', 'name').focus();
    document.forms['example'].submit();
    "
    but i get new window opened without posted data and in the page that i have pressed button i get posted data which should be in new window.
    Could somebody correct my code?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You need to target the window from the form, and you may as well use a normal submit button, forget about onclick, and use the onsubmit of the form to open the new window. This may need some tweaking (like a timeout to give the window time to open before the form actually submits or moving the window open to an onmousedown of the submit button to open the window, also with the idea being to get the window open in time for the actual submission), but we will worry about that if there is a problem. So I would do something like:

    Code:
    <form action="new.html" target="submission" 
    onsubmit="window.open('',this.target);return true;" method="post">
    Your Form Contents Here
    <input type="submit" value="Submit">
    </form>
    new.html should be the name of the page you are posting to.

    Added Later:

    But this can be done without javascript:

    Code:
    <body>
    <form action="new.html" target="_blank" method="post">
    Your Form Contents Here
    <input type="submit" value="Submit">
    </form>
    Last edited by jscheuer1; 09-30-2008 at 05:00 AM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thx for help. It really works. But my script is now bigger and I've got another problem.
    I've got menu using CSS sytle and it's outside the form.

    Code:
    <form action="new.html" target="_blank" method="post">
    My Form Contents Here
    </form>
    
    // menu 
    <input type="submit" value="Submit">
    I want to post some data using this menu and refresh site after post. How can I submit outside the form. I'm using java script but I got a problem. 1st time when I click it seems to doesn't work but after clicking second time it works fine. I'm posting my data and storing them into cookies.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    As far as submitting the form from the menu goes, the easiest thing would be to include the menu in the form. It won't hurt anything if it is well planned out:

    HTML Code:
    <form action="whatever" target="_blank" method="post">
    Form contents Here
    
    <!-- Menu -->
    
    <input type="submit" value="Submit">
    
    <!-- End Menu -->
    </form>
    If you want the form proper to have an outline or anything special as far as style goes, and have that be different than the menu, use something like:

    HTML Code:
    <form action="whatever" target="_blank" method="post">
    
    <div id="formstyles">
    Form contents Here
    </div>
    
    <!-- Menu -->
    
    <div id="menustyles">
    Other Menu Stuff Here
    <input type="submit" value="Submit">
    Other Menu Stuff Here
    </div>
    
    <!-- End Menu -->
    </form>
    You can use whatever ids, or even classes if you like for the two divisions to get different styles in the two areas. But it will still be all one form. Care should be taken not to name any inputs in the menu section whose values you don't want to receive on post. But, as long as your server side code isn't looking for values from inputs with those names, even that shouldn't hurt anything. I only mention this in case you have other input elements in the menu area and need to use their name attributes for other purposes.

    You can even have all sorts of stuff in between the 'end' of the form proper and the beginning of the menu, probably just not other forms.

    Bottom line, as long as it's valid HTML, forms don't care how much other stuff is inside their opening and closing tags. Other (complete) forms may even be OK, I just wouldn't want to guarantee it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Is there any posibility to use html anchors to submit target or any other html element which can be override in css style?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by lupos View Post
    Is there any posibility to use html anchors to submit target or any other html element which can be override in css style?
    I don't see why you want to override css style, instead use it as you like building upon the second example from my last post.

    The menu can be styled one way and the the area in the form you want set apart can be styled another. The form itself need not be used to style any of its contents - that's what the divisions are for.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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