post form to new window; preserve original form action property

Discussion in 'Javascript' started by Bosconian, Dec 3, 2006.

  1. Bosconian

    Bosconian Guest

    I have created a form tool page that consists of several dropdowns which
    allows a user to drill down and select a desired document for viewing in an
    external window. I need to post the form data to the external window so the
    values can be used to retrieve the appropriate document.

    The function below will open the window and post the form data accordingly,
    but when defining the action property it changes the original form action
    property. I need to preserve the original form action property so the user
    can switch back to the form tool window and retrieve additional documents.

    What's the method for preserving the original form action property?

    Thanks in advance.

    -------------------------------------------

    function newWindow() {
    var newForm = document.forms[0];
    window.open('newpage.php','newtarget','resizable=yes,scrollbars=yes,width=800,height=600'); newForm .target = 'newtarget'; newForm .method = 'post'; newForm .action = 'newpage.php'; return true;}
    Bosconian, Dec 3, 2006
    #1
    1. Advertising

  2. Bosconian wrote:
    > I have created a form tool page that consists of several dropdowns which
    > allows a user to drill down and select a desired document for viewing in an
    > external window. I need to post the form data to the external window so the
    > values can be used to retrieve the appropriate document.
    >
    > The function below will open the window and post the form data accordingly,


    I don't see newForm.submit() in this function so the submission happens
    somewhere else? Are you calling newWindow() from the onsubmit attribute
    of the form element or from the onchange attribute of the select
    element? Can you post a 30 line complete page that shows the form and
    this newWindow function and how the two interact?


    > but when defining the action property it changes the original form action
    > property. I need to preserve the original form action property so the user
    > can switch back to the form tool window and retrieve additional documents.


    After you submit the form you could reset the action to the original
    which you either just know or you can store before you make the first
    change.


    > -------------------------------------------
    >
    > function newWindow() {
    > var newForm = document.forms[0];
    > window.open('newpage.php','newtarget','resizable=yes,scrollbars=yes,width=800,height=600'); newForm .target = 'newtarget'; newForm .method = 'post'; newForm .action = 'newpage.php'; return true;}
    Peter Michaux, Dec 3, 2006
    #2
    1. Advertising

  3. Bosconian

    ASM Guest

    Bosconian a écrit :
    > I have created a form tool page that consists of several dropdowns which
    > allows a user to drill down and select a desired document for viewing in an
    > external window. I need to post the form data to the external window so the
    > values can be used to retrieve the appropriate document.


    it is quite simple

    <form action="searchDatas.php" target="viewer" method="get"
    onsubmit="return displayDoc();">

    function displayDoc() {
    var f = document.forms[0];
    if(f.doc.checked) {
    var attr = 'resizable=yes,scrollbars=yes,width=800,height=600'
    f.target = 'viewer';
    if(typeof(newDoc)=='undefined' || !newDoc || newDoc.closed)
    newDoc = window.open('','viewer',attr);
    newDoc.focus();
    return true;
    }
    f.target = '_self';
    return true;
    }

    In your form in your main mother window
    you put a checkbox to allow popup or not

    Doc in a popup <input type=checkbox name="doc" checked>

    > function newWindow() {
    > var newForm = document.forms[0];
    > window.open('newpage.php','newtarget','resizable=yes,scrollbars=yes,width=800,height=600'); newForm .target = 'newtarget'; newForm .method = 'post'; newForm .action = 'newpage.php'; return true;}


    there is nothing here to change action of your form ... ! ?


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
    ASM, Dec 3, 2006
    #3
  4. Bosconian

    Bosconian Guest

    "Peter Michaux" <> wrote in message
    news:...
    > Bosconian wrote:
    >> I have created a form tool page that consists of several dropdowns which
    >> allows a user to drill down and select a desired document for viewing in
    >> an
    >> external window. I need to post the form data to the external window so
    >> the
    >> values can be used to retrieve the appropriate document.
    >>
    >> The function below will open the window and post the form data
    >> accordingly,

    >
    > I don't see newForm.submit() in this function so the submission happens
    > somewhere else? Are you calling newWindow() from the onsubmit attribute
    > of the form element or from the onchange attribute of the select
    > element? Can you post a 30 line complete page that shows the form and
    > this newWindow function and how the two interact?
    >
    >
    >> but when defining the action property it changes the original form action
    >> property. I need to preserve the original form action property so the
    >> user
    >> can switch back to the form tool window and retrieve additional
    >> documents.

    >
    > After you submit the form you could reset the action to the original
    > which you either just know or you can store before you make the first
    > change.
    >
    >
    >> -------------------------------------------
    >>
    >> function newWindow() {
    >> var newForm = document.forms[0];
    >>
    >> window.open('newpage.php','newtarget','resizable=yes,scrollbars=yes,width=800,height=600');
    >> newForm .target = 'newtarget'; newForm .method = 'post'; newForm .action
    >> = 'newpage.php'; return true;}

    >


    Ok, I got things sorted. I took your suggestion and restored the original
    action property value after submission (which was mistakenly omitted from my
    original message.) I'm also resetting the target property to '_self'.

    Thanks for your reply.
    Bosconian, Dec 3, 2006
    #4
  5. Bosconian

    Bosconian Guest

    "ASM" <> wrote in message
    news:4572bf30$0$27388$...
    > Bosconian a écrit :
    >> I have created a form tool page that consists of several dropdowns which
    >> allows a user to drill down and select a desired document for viewing in
    >> an external window. I need to post the form data to the external window
    >> so the values can be used to retrieve the appropriate document.

    >
    > it is quite simple
    >
    > <form action="searchDatas.php" target="viewer" method="get"
    > onsubmit="return displayDoc();">
    >
    > function displayDoc() {
    > var f = document.forms[0];
    > if(f.doc.checked) {
    > var attr = 'resizable=yes,scrollbars=yes,width=800,height=600'
    > f.target = 'viewer';
    > if(typeof(newDoc)=='undefined' || !newDoc || newDoc.closed)
    > newDoc = window.open('','viewer',attr);
    > newDoc.focus();
    > return true;
    > }
    > f.target = '_self';
    > return true;
    > }
    >
    > In your form in your main mother window
    > you put a checkbox to allow popup or not
    >
    > Doc in a popup <input type=checkbox name="doc" checked>
    >
    >> function newWindow() {
    >> var newForm = document.forms[0];
    >>
    >> window.open('newpage.php','newtarget','resizable=yes,scrollbars=yes,width=800,height=600');
    >> newForm .target = 'newtarget'; newForm .method = 'post'; newForm .action
    >> = 'newpage.php'; return true;}

    >
    > there is nothing here to change action of your form ... ! ?
    >
    >
    > --
    > Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    > Stephane Moriaux and his (less) old Mac already out of date


    Thanks for your reply.

    Your function was instructive and helped me sort out the requirements for my
    app. The action property must be redefined so that it points to the new
    window only after the last selection. The original action property is then
    restored so that the original form page will continue to work correctly.
    Bosconian, Dec 3, 2006
    #5
    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. Matt
    Replies:
    2
    Views:
    13,912
    bruce barker
    Aug 23, 2004
  2. Matt
    Replies:
    1
    Views:
    410
    Andrew Thompson
    Aug 22, 2004
  3. Matt
    Replies:
    5
    Views:
    3,024
    Michael Winter
    Aug 25, 2004
  4. Matt
    Replies:
    3
    Views:
    210
    Bob Barrows [MVP]
    Aug 22, 2004
  5. Matt
    Replies:
    2
    Views:
    197
    Harag
    Aug 23, 2004
Loading...

Share This Page