Results 1 to 5 of 5

Thread: Opening a new window from a form submit

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

    Default Opening a new window from a form submit

    Hello, I have a form in which I have set up a preview page that appears in a new window in which the user can browse their content. I have that working fine however my regular submit button now directs to this preview pop up page which i certainly don't want to happen.

    Code:
    <head>
    <script>
    function cForm(form)
     win=window.open('','myWin','toolbars=0');
     form.target='myWin';
     form.action='prev_event.php'
    }
    </script>
    </head>
    Code:
    <INPUT type="submit" name="action" value="Publish Article">
    <input name="buttonB" type="submit" value="Preview" onclick="cForm(this.form)">
    Any suggestions anybody.

    Thanks

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    You don't want to have it on the submit button. In your forum tag:
    HTML Code:
    <form>
    Add this:
    HTML Code:
    <form onsubmit="cForm(this)">
    I took off this.form, and made it this because it's on the form.
    Last edited by Nile; 06-26-2008 at 02:05 PM.
    Jeremy | jfein.net

  3. #3
    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

    For the events of form elements, this.form is perfectly good.

    The problem here is that you have two submit buttons.

    If only one is required, only one should be used, the other can be an ordinary button that does something.

    You might consider two forms, each with their own submit button. The data in the second form could be copied and/or cloned from the first and be largely or totally unseen by the user.
    - John
    ________________________

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

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    An ordinary button as I recall is this:
    HTML Code:
    <button>Hello</button>
    If he uses this then it will act as a submit button to as I remembered when I did that.
    So he'd need to use an input type="button:
    HTML Code:
    <input type="button" value="Hello">
    Correct me if I'm wrong, please.
    Jeremy | jfein.net

  5. #5
    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

    If the form has a submit button, other buttons should not submit it. Generally the button tag should not be used, as everything you can do with it can be done with the more standard input tag with its type set as 'button'.

    Here is an example of what (using two forms) I am talking about (tested in FF only):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 
    Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <form action="#">
    <div>
    <input type="text" name="bob" value="something"><br>
    <textarea name="sid" cols="50" rows="5">Hi There Folks!</textarea><br>
    <input type="submit" value="s1">
    </div>
    </form>
    <form action="#" target="_blank" onsubmit="for (var els1 = document.forms[0].elements, i = els1.length - 1; i > -1; --i)
    if(els1[i].value && els1[i].name && this.elements[els1[i].name])
    this.elements[els1[i].name].value = els1[i].value;
    return true;">
    <div>
    <input type="hidden" name="bob"><input type="hidden" name="sid">
    <input type="submit" value="s2">
    </div>
    </form>
    </body>
    </html>
    - 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
  •