Search code examples
javascriptformshttp-redirectwindow.openonsubmit

onsubmit property fails to open new window


A quick question here regarding forms. I've searched the web and can't seem to figure out why what I've implemented isn't working.

The idea is simple. I have a form inside a JSP page. The form has an 'onsubmit' property defined to open a different jsp with some parameters. Inside the form I have a few buttons, one of which calls a JavaScript function, which in turn submits the form (under some conditions).

Here's the code: JSP:

...
<form id='testForm' onsubmit="window.open('another.jsp')">
  <input type="button" onclick="callJsFunction()" />
  ..
</form>

JavaScript:

function callJsFunction() {
  if (launchNow == 1) {
    var form = document.getElementById("testForm");
    form.submit();
  }
}

If I add target="_blank" to the form definition, a new window does open, but NOT the jsp I want to open. Ultimately, I want the form to perform a servlet action (using the action attribute) and then open the new jsp. Any ideas???

Thanks!


Solution

  • The solution to what I was looking for is found here: Javascript Post on Form Submit open a new window

    Rather than setting target="_blank", I can set the target to the window I define and open. In my servlet, I redirect to the desired jsp, and it appears in the new pop-up window.