Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jsp and javascript Problem

Status
Not open for further replies.

GooDog

Programmer
Feb 11, 2002
34
IN
Hi All,
I have a jsp page with some javascript fucnctions and with two buttons as "Print" and "Cancel".While opening this jsp i am getting some datas from database and displaying them.When the user clicks the "Print" button i want to insert some of the datas in the data base.For that i am calling a javascript function inside which i am calling the javascript print command to print the page.And i have written the jsp code to insert the datas in to the database.Here my problem is the jsp code executes when the jsp page opens itself and the insert query executes.I want to stop this onloading of the page.Is there any way to do this.

Thanks in advance,
Prakash
 
Prakash,

Your meaning is not quite coming across. When you refer to inserting the data (when the 'Print' button is hit), do you mean inserting INTO THE DATABASE or ONTO THE PAGE that is being printed? If "into the database," what are you inserting? The same data that was retrieved from the database when the page loaded? If "onto the page," are you just trying to add something to the printout? If yes, then do what you're doing, but wrap the things you only want printed in SPAN tags such as <span class='printOnly'>Page 1</span>

Then the printOnly class would be defined in your css:

<style media='screen'>
.printOnly{
visibility:hidden; /*or display:none... depending */
}
</style

<style media='print'>
.printOnly{
visibility:visible; /*or display:inline or display:block*/
}
</style>

Is that what you're after?

--Dave
 
Hi Dave,
Thanks for the reply.Actually i am retiriving the values from the data base and doing some calculations and display them.If that is ok for the user then he will hit the "Print" button.At that time the displayed datas will print and the calculated values will be inserted to the database.But onload of the page itself the datas are inserting in to the database.printing is not a problem.Only i want to avoid the insertion during the page onload.Please guide me a solution.

Prakash
 
On your page with the displayed calculations, you can include the following HTML:

Code:
<iframe id='WORK_FRAME' src='insertCalcs.html' width='0%'></iframe>

Then create insertCalcs.html as an HTML form with action='insertCalcs.jsp' and which has hidden elements for each value you'll want inserted.

For example:
Code:
<html><body><form method='POST' action='insertCalcs.jsp'>
<input type='hidden' name='density' />
<input type='hidden' name='maxTemp' />
</form></body></html>
[code]

Then, create insertCalcs.jsp to take the sent information (in this case, density and maxTemp) and insert it into the table you want.

Finally, have your print button call a JavaScript function such as:

[code]
function printMe()
{
 var f = document.frames['WORK_FRAME'].document.forms[0];
 f.density.value = calculatedValue1;
 f.maxTemp.value = calculatedValue2;
 f.submit();

 window.print();
}

Let me know if you follow this.

There are other ways this can be done.

--Dave
 
Hi Dave,
Thanks a lot.It works fine.Please let me know some of the other ways to achive this.(Just for knowledge sake). Thanks you very much again.

Regards,
Prakash
 
Prakash,

THE other I was thinking of was, instead of putting an HTML form in the hidden IFRAME, you could just put something like this in your printMe() function:

Code:
document.frames['WORK_FRAME'].document.location = 'insertCalcs.jsp?density="+calculatedValue1+"&maxTemp="+calculatedValue2;

This is more of a 1-step approach while the other was 2-step (fill out form, then submit). I think the two-step is neater and more universally applicable (using the method='POST' allows many more parameters to be sent that this method which calls the JSP directly).

Anyway, I'm glad it works. Happy New Year!

--Dave
 
Hi Dave,
Thanks for your suggestions.Happy New Year.

Regards,
Prakash
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top