jQuery: recreating a form's contents in hidden fields on a 2nd page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • svendok
    New Member
    • Jun 2010
    • 25

    jQuery: recreating a form's contents in hidden fields on a 2nd page

    I have a CGI-style web application using static HTML (an SAS IntrNet app) that submits a form to the server and then gets a report back.

    I want to change it so that the output is opened in a separate window which gets created using JavaScript.

    That means I need to grab all the form selections and hidden fields and pass them to the new window, plug them into a new form and submit to the server.

    What's the best way to do this? Is this the most efficient way?

    1. Loop through the form using jQuery and populate a querystring variable with all the form elements' names & values. (Note: Some are multi-option select boxes.)
    2. Open up the new window with that querystring.
    3. Loop through that querystring and dynamically add a hidden field to the window's form for each element.
    4. Submit the form from the window to the server.

    Are there any gotchas I need to be aware of? Can hidden fields take the place of multiple-value select boxes, for example?

    I've figured out how to loop through the form using jQuery and create the querystring. Now, I just want to make sure the final step--impersonating the original form--is doable, too.

    Thanks.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Instead of that, why can't you set the target attribute so that it opens in a new window (avoiding the need for any JavaScript)?

    Comment

    • svendok
      New Member
      • Jun 2010
      • 25

      #3
      Man, I'm an idiot. That's so simple, it's obscene. Thank you!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        No problem. Sometimes it's just a case of finding a simpler solution. Having said that, it may be an idea to solve the problem that you posed to improve your skills/expertise.

        Comment

        • svendok
          New Member
          • Jun 2010
          • 25

          #5
          True. The target solution isn't perfect in this case, since IE doesn't allow you to close that window using window.close() (FF does). So the IE user has to click a confirmation message every time. But I can live with that for now.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You can use window.open() with the window name and then use that as the target in the form. See https://developer.mozilla.org/en/DOM...and_parameters

            Comment

            • svendok
              New Member
              • Jun 2010
              • 25

              #7
              Hmm, the plot thickens. Thank you yet again!

              Comment

              Working...