1

I have a jsp page in struts 1.2 which has 2 functionalities. Print pdf and submit form.
Print pdf will open a new window and display a pdf generated with the field values in the page.
Submit form should navigate to confirmation page in the same window and save values in db.
Here are the part of code for it.

<a href="javascript:void(0)" onclick="javascript:printPDF();" target="_blank"><img src="/images/buttons/ButtonPrint.gif" border="0" alt="Print" ></a>

<a href="javascript:void(0)" onclick="javascript:submitContinue();"><img src="/images/buttons/ButtonSubmit.gif" border="0" alt="Submit" ></a>


Here are the corresponding javascript methods.

function submitContinue()
{
    document.forms[0].action = "/provider/requestSubmitted.do?method=processUpload";
    document.forms[0].submit();
    return true;
}

function printPDF()
{
    document.forms[0].action = "/provider/requestSubmitted.do?method=printPDF";
    document.forms[0].target="new";
    document.forms[0].submit();
    return true;

}

These functionalities works fine separately. But if I click on print and then on submit, the next page(confirmation page) opens in a new tab. It should be in the same window. Please help !!

4
  • 1
    remove target="_blank" Commented Nov 1, 2013 at 11:33
  • Why this line in printPDF()? -> document.forms[0].target="new"; Commented Nov 1, 2013 at 11:33
  • @Manish: Its to open the pdf in a new window Commented Nov 1, 2013 at 11:36
  • @rajeshkakawat: Tried. But didn't work. But I don't have a target attribute for submit anyway. Commented Nov 1, 2013 at 11:38

2 Answers 2

2

Jijo,

you have a script to submit a form, in your form object to submit has a target attribute, when the target has value new or xxx (tab name) this works fine, you must remove the target value from your form object.

 function submitContinue()  
 {
    document.forms[0].action = "/provider/requestSubmitted.do?method=processUpload";
    document.forms[0].target="_self";
    document.forms[0].submit();
    return true;
}  
 function printPDF()
 {
     document.forms[0].action = "/provider/requestSubmitted.do?method=printPDF";
     document.forms[0].target="pdf";
     document.forms[0].submit();
     return true; 
 }

if you have

 <form action="xxx" **target="yyy"**

you must remove again target="yyy"

The documentation about target attribute is

target values      Description
  _blank            Specifies where to display the response that is 
  _self
  _parent
  _top
Sign up to request clarification or add additional context in comments.

2 Comments

It worked fine. Thanks !! I've another issue now. In IE8, the PDF link which gets opened in new window displays a "Page Cannot be Found" page first. I have to refresh the page to display the pdf. Any idea why is it so??
only in IE8 have you this problem?
1
function submitContinue()
{
    document.forms[0].action = "/provider/requestSubmitted.do?method=processUpload";
    document.forms[0].target=self; <-------HERE
    document.forms[0].submit();
    return true;
}

when you use printPDF the form target is set to "new", and if you don't refresh the page or reset it to "self" (or null) that form will open a new window on every submit.

2 Comments

Tried. But didn't work. When I click on submit, I guess it first opens a window then only going through the javascript function. Should I try refreshing the page after every time I click on print ?
no, the form is executed on "submit()" so the new windows will open on "submit()" too. check if your page has not been cached, see the source in the browser and check for this change to be present

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.