Submit form to pop-up - why does this code not work?

Discussion in 'Javascript' started by jeff@dnuk.com, Sep 26, 2003.

  1. Guest

    I want to press a submit button on a form and then a pop-up Window opens
    to process the form data.


    I have a form with this HTML code:

    <form action="/test.php" method="post" name="testform" onSubmit="newWindowForm('testform')">


    And here is the javascript for the top of the page:

    function newWindowForm(formname)
    {
    //alert(formname);
    var popUp = window.open ('','popUp','scrollbars=no,resizable=no,width=450,height=350');
    document.formname.target = 'popUp';
    }


    The problem is this line:

    document.formname.target = 'popUp';


    I've obviously got the syntax wrong. I've checked that the "formname" parameter
    is being passed to the javascript, it is. You can test it by using the
    "alert(formname);" line to see what it is.

    A quick way to fix this is to harcode the formname into the javascript:

    document.testform.target = 'popUp';


    However, there will be lots of these forms in my website and I want
    to use 1 piece of code for each form, instead of coding each javascript.

    Can this be done?

    Cheers
     
    , Sep 26, 2003
    #1
    1. Advertising

  2. wrote:

    > I want to press a submit button on a form and then a pop-up Window opens
    > to process the form data.
    >
    >
    > I have a form with this HTML code:
    >
    > <form action="/test.php" method="post" name="testform" onSubmit="newWindowForm('testform')">
    >
    >
    > And here is the javascript for the top of the page:
    >
    > function newWindowForm(formname)
    > {
    > //alert(formname);
    > var popUp = window.open ('','popUp','scrollbars=no,resizable=no,width=450,height=350');
    > document.formname.target = 'popUp';
    > }
    >
    >
    > The problem is this line:
    >
    > document.formname.target = 'popUp';
    >


    I guess you want
    <form target="windowName"
    onsubmit="window.open('', this.target, 'width=...');
    return true;"

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Sep 26, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,999
    Smokey Grindel
    Dec 2, 2006
  2. Guest
    Replies:
    2
    Views:
    1,603
    Guest
    Oct 25, 2004
  3. samppi
    Replies:
    27
    Views:
    494
    David A. Black
    Dec 5, 2007
  4. Marco Alting
    Replies:
    7
    Views:
    516
    Thomas 'PointedEars' Lahn
    Oct 30, 2003
  5. Megha Vishwanath
    Replies:
    3
    Views:
    718
    Megha Vishwanath
    Jul 20, 2004
Loading...

Share This Page