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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jeff@dnuk.com

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

    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="newWi ndowForm('testf orm')">


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

    function newWindowForm(f ormname)
    {
    //alert(formname) ;
    var popUp = window.open ('','popUp','sc rollbars=no,res izable=no,width =450,height=350 ');
    document.formna me.target = 'popUp';
    }


    The problem is this line:

    document.formna me.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.testfo rm.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
  • Martin Honnen

    #2
    Re: Submit form to pop-up - why does this code not work?



    jeff@dnuk.com wrote:
    [color=blue]
    > 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="newWi ndowForm('testf orm')">
    >
    >
    > And here is the javascript for the top of the page:
    >
    > function newWindowForm(f ormname)
    > {
    > //alert(formname) ;
    > var popUp = window.open ('','popUp','sc rollbars=no,res izable=no,width =450,height=350 ');
    > document.formna me.target = 'popUp';
    > }
    >
    >
    > The problem is this line:
    >
    > document.formna me.target = 'popUp';
    >[/color]

    I guess you want
    <form target="windowN ame"
    onsubmit="windo w.open('', this.target, 'width=...');
    return true;"

    --

    Martin Honnen


    Comment

    Working...