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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding items when printing 4

Status
Not open for further replies.

abuthemagician

IS-IT--Management
Nov 26, 2003
192
US
I have a form i created that has a print button at the end of the form. When you click the button the form prints WITH the print button. I know in VB there is a way to hid the button just before being sent to the printer. Can this be done with html or even Javascript?
 
why the background colors? Also, the form is on a local intranet that is not accessable from the web.
 
the <span class="noprint">YOUR BUTTON STUFF</span>
fixed it! now i just have to get it into the other file and life will be peachy keen
 
I can't believe I typed 'style' rather than 'class' in my comment. Good thing Clive was awake. [blush]

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
now, to put the icing on the cake, can i use CSS to hide the inet address in IE as well as the page numbering?
 
the css file will be in a diff directory, but the ../dir/print.css works now that the code is right. I still have a lot of reading to do in regards to CSS
 
... can i use CSS to hide the inet address in IE as well as the page numbering?
That's a browser setting that the user would have to adjust (as far as I know). Someone here may have a better answer.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Yeah it already does, i was posting code from a different post and never modified the name of the button to reflect my real configuration. The form was also written by my predecessor who was a programmer, something i am not (I almost failed numbers and logic in college).
 
Place this script in your header.

Use the div tag "<div id="printReady">" for the area you want printed... and end BEFORE your print button.

<script language="JavaScript">
var gAutoPrint = true;

function printSpecial()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';

if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}

html += '\n</HE' + 'AD>\n<BODY>\n';

var printReadyElem = document.getElementById("printReady");

if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady section in the HTML");
return;
}

html += '\n</BO' + 'DY>\n</HT' + 'ML>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("Sorry, the print ready feature is only available in modern browsers.");
}
}

</script>

and then within your <body> tag

<div id="printReady">

Content you want printed...

</div>

 
Charles, could you please share with us what is the point of this longwinded approach that might not even work on all browsers if the same can be achieved by one or two lines in css and works cross-browser?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top