Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    window open method=post

    Situation: adding code to an HTML page that I can add to, but not change any existing code, as it is from a vendor and gets generated on the fly. I need to add a button within the existing <form></form> construct that already has a submit button and the form has an "action=" in it.

    What I have done is added <input type=button onClick=myscript().... Myscript() opens a .php file as a popup, positions it correctly, and all that. What it doesn't do is move the values to the .php like a method=POST would. Is there anyway to to do this, or do I have to do a set of document.write statements?

    Existing code:
    Code:
    <!-- vendor's untouchable code -->
    <form method=post name="MainForm" action="xxx.asp?yyy" onsubmit="the_vendors_code();>
    
    <input type="text" name="fielda" value="" >
    <!-- several more fields -->
    
    <!-- my code -->
    <SCRIPT type="text/javascript" SRC="xxx.js"></SCRIPT>
    <SCRIPT type="text/javascript">
    function popupForm(myForm, windowName)
    {
      var scrny=0 ;
      var scrnx=200
    <-! code to set scrny and scrnx based on browser -->
      fielda_h.value = fielda.value ;
    <!-- etc ..>
    
    <!-- here's the place I need help -->
    newWin= window.open("myPopup.php", windowName, 'height=600,width=550,and a whole bunch of other parameters') ;
    newWin.moveTo(scrnx, scrny) ;
    myForm.target=windowName;
    return true ;
    }
    </script>
    
    <input type="hidden" name="fielda_h" >
    <input type="button" name="preview" value="See Preview" onClick="popupForm(this, 'join')"/>
    Note that some of the code was taken from examples found on the net, so there's not a ton of originality here.

    So, again, just to restate, I know how to do a submit button/form to do action=post, but I am trying to simulate it with a regular button as I cannot change the existing <form></form> construct.

    Thanks for any and all pointers.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,014
    Thanks
    79
    Thanked 4,436 Times in 4,401 Posts
    Code:
    <SCRIPT type="text/javascript">
    function popupForm(myForm, windowName)
    {
        var scrny=0 ;
        var scrnx=200
        <-! code to set scrny and scrnx based on browser -->
        fielda_h.value = fielda.value ;
    
        // open a *BLANK* WINDOW!!!!
        newWin= window.open("", windowName, 'height=600,width=550,and a whole bunch of other parameters') ;
        newWin.moveTo(scrnx, scrny) ;
    
        // save form info:
        var saveTarget = myForm.target;
        var saveAction = myForm.action;
        var saveMethod = myForm.method; // not needed if already post
    
        // change form info:
        myForm.target = windowName;
        myForm.action = "myPopup.php";
        myForm.method = "post"; // not needed if <form> was already post
        myForm.submit( );  // invoke the form, submitting to the popup window
    
        // restore form:
        myForm.target = saveTarget;
        myForm.action = saveAction;
        myForm.method = saveMethod; // if used
    
        return true ; // why does this matter? ordinary buttons ignore return value
    }
    </script>
    NOTE: The vendor's code that occurs via onsubmit of the form is *NOT* invoked when you do this! Calling submit function directly bypasses the onsubmit. If you need it called, then do so before calling submit().
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    alan_b56 (06-15-2010)

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Soved with work-around

    thanks Old Pedant.

    I came up with a not very elegant solution, but I got the desired results by
    1) create cookies
    2) open "hidden" html file which reads the cookies, populates the text boxes, and self-clicks the "submit" button, which
    3) calls the .php and closes itself.

    btw, the "return true" is just a (bad) habit I got in to.


  •  

    Tags for this Thread

    Posting Permissions

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