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!

window.print() returns error

Status
Not open for further replies.

ttuser4

MIS
Jun 19, 2008
147
CA
I have one page which shows results/calculation of previous input. on the bottom of this page is option to print the page using the window.print() function. it does print the page but then gives an error message (see below) - it looks like it wants to recalculate the results but it doesn't have all input data this fails. any idea how to fix this problem, please?


code:

<script type="text/javascript">
function printpage()
{
window.print()
}
</script>
...
...
...
<a href="" onclick="printpage()" >Print this page</a>

error:

Warning: Division by zero in /webcalc_output.php on line 144

Warning: Division by zero in /webcalc_output.php on line 151
Use BACK button and correct your total length.
 
well, I fixed it with using this code instead

<input type="button" value="Print this page" onclick="window.print()" />
 
This might also have fixed it:

Code:
<a href="javascript:void(0);" onclick="printpage()" >Print this page</a>

You should also add a semi-colon after window.print() in your function.

The error you were getting probably had nothing to do with the javascript, looks like there is an error elsewhere on the page.

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
thanks.
yes, javascript 'window.print()' didn't cause the problem.
i think the issue was this part href=
 
if you don't specify a value for href, it will simply re-load the current page getting rid of any data that was posted to it via a form (for example).

That might have been why you were getting an error.

You could also have done it like this:

Code:
<a href="javascript:window.print();">Print Me!</a>

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top