hall
Mar 8th, 2001, 12:38 PM
Help!! I have a web page on which I get a number of inputs from the user and then submit a form back to the server to build another page in a different target window based on the user selected values in the first page. The problem is that I want to print the target window as soon as it is opened using a “window.print()” command in some form. I don’t want the user to have to click something in the target window because when he submits the form from the first page, he already thinks he is getting a printout with the relevant data. I know this sounds picky but I have my reasons. I thought I could just put some script at the bottom of web page 2 as shown in the example below but it doesn’t work properly.
<!-- Abbreviated contents of file that submits the form back to the server. Web Page 1 -->
<form method=post action=printprob.asp name=form2 target=_blank>
<button type=submit >Print This </button>
<!-- Abbreviated contents of the printprob.asp file that was called by the first page. Web Page 2-->
<html>
<%
n=0
do until n=2
%>
This is a test.
<br>
<%n=n+1
loop%>
</html>
<script>
window.print()
</script>
When you run this, the first time you will get an HTML file with two lines of “This is a test.” therein in the targe window and that file will be printed properly. However, now if you change the do until n=2 to n=10 and resubmit, the target window will open with “This is a test.” 10 times but the printed output will still contain only 2 lines of “This is a test.” It seems that stale window contents are being printed from somewhere. I’m a relative novice at this so I realize that this is probably not the best way to do this even if I get it working. Ideally, I could send the info back to the server, build the second file and print it without even having to open it in a new target window. Any help will be greatly appreciated.
Thanks very much,
KBH
<!-- Abbreviated contents of file that submits the form back to the server. Web Page 1 -->
<form method=post action=printprob.asp name=form2 target=_blank>
<button type=submit >Print This </button>
<!-- Abbreviated contents of the printprob.asp file that was called by the first page. Web Page 2-->
<html>
<%
n=0
do until n=2
%>
This is a test.
<br>
<%n=n+1
loop%>
</html>
<script>
window.print()
</script>
When you run this, the first time you will get an HTML file with two lines of “This is a test.” therein in the targe window and that file will be printed properly. However, now if you change the do until n=2 to n=10 and resubmit, the target window will open with “This is a test.” 10 times but the printed output will still contain only 2 lines of “This is a test.” It seems that stale window contents are being printed from somewhere. I’m a relative novice at this so I realize that this is probably not the best way to do this even if I get it working. Ideally, I could send the info back to the server, build the second file and print it without even having to open it in a new target window. Any help will be greatly appreciated.
Thanks very much,
KBH