0

I've got a form that has three submit buttons for posting back data for different scenarios.

Each one POSTs to different actions on a controller, however for one of them I need to POST back to a new browser window.

Is this possible? I know I can add a target="_blank" to the form, but that will open a new window for all of the submit buttons...

UPDATE:

Currently, I've tried several methods to get this working and I've completely failed, my current non-working code looks like this:

$("input[type=submit]").click(function (e) {
    var form = $("form.filter-execution-form");
    if ($(this).hasClass("run-report"))
        $("form.filter-execution-form").attr("target", "_blank");
    else
        $("form.filter-execution-form").removeAttr("target");
});

Does anyone have any ideas to get this working?

Thanks,
Kieron

Kieron
  • 26,748
  • 16
  • 78
  • 122
  • Write a Javascript method that precedes the submit and adds the `target` attribute to the form – Zruty Jul 05 '11 at 15:37

4 Answers4

1

There are probably a number of different ways to do this. The easiest I can imagine is when the submit button is pressed in the first window, you open a new window with a URL (on the same domain) that has the desired form in it (may have to watch out for pop-up blockers). Then, transfer the data that has been entered from your existing form to the form in the new window. Call a javascript function in the new page that tells it to submit the form.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
1

See this post - use the same method to dynamically add the attribute for the submit button you want it for (ie add it to the onclick event of your submit button you want to add this support to)

How do I add target="_blank" to a link within a specified div?

Community
  • 1
  • 1
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • Based on that article, I eventually managed to figure it out. It all seems pretty *hacky* - but got there. – Kieron Jul 11 '11 at 20:26
0

The best way I can think of doing this (and it might not be the best way of doing it) would be using JavaScript.

When you click the button, prevent it doing anything but run some javascript instead, open a new window on a blank page, with a hidden form in it, use javascript to transfer values from your form to the new pop-up form, submit the pop-up form & do something with original page to show an action was taken.

Naftali
  • 144,921
  • 39
  • 244
  • 303
Simon Halsey
  • 5,459
  • 1
  • 21
  • 32
0

In the form set target="postWindow" or any other name that is the same throughout, and it will always post to that popup (if it was not closed).

Naftali
  • 144,921
  • 39
  • 244
  • 303