hiding, showing and printing in javascript

M

Mike P

I am trying to print a webpage and making some objects invisible for the
print, and then visible again after. But my code does not work :

function PrintInvoice()
{
document.getElementById("Button1").style.visibility = "hidden";
document.getElementById("Button2").style.visibility = "hidden";

window.print();

document.getElementById("Button1").style.visibility = "visible";
document.getElementById("Button2").style.visibility = "visible";
}

Can anybody with good javascript skills help?
 
M

Mike P

Found the error - it was simply a matter of calling the function without
braces i.e. PrintInvoice instead of PrintInvoice().
 
E

Eliyahu Goldin

There are two javascripts events onbeforeprint and onafterprint that are
good for placing this type of code in. It will make sure that the page
prints correctly regardless of the way how you initiate print, even if the
user clicks the browser's Print button.

And the css idea that the other poster suggested is even better.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top