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

print 2

Status
Not open for further replies.

mimi2

Technical User
Joined
Apr 2, 2002
Messages
407
Location
CA
hello,
i would like to print my preview page. on the left there's the menus and other stuff that should not be printed.
<input type=&quot;button&quot; value=&quot;Print&quot; onClick=&quot;javascript:window.print();&quot;> is not a solution for me.
what i am thinking about is opening a new document(invisible), write the info in and then print.
how can i do all this, and is it possible ?
thanks
 
Don't use javascript: inside event handlers.

Your idea of opening up a separate window with just the information in it that you want printed is the only way to accomplish what you want, though you shouldn't make the information &quot;invisible&quot;, or it will print that way - invisible. If you blur() the window that you're printing, it won't be in the way of the main window.
 
thanks. could you give a hint on how to do that ? i am not a javascript guru (yet)
 
Show your code for what you have now to make the separate window, and then we can go from there.
 
thanks. here's my stuff.

<SCRIPT LANGUAGE =&quot;JavaScript&quot;>
<!--
function PrintMyForm() {
var Request_reason = new Array();
var RdOpinion = document.Form2.RdOpinion.value;
for (var i = 1 ; i <= 16 ; i++) {
Request_reason (i) = document.Form2.Request_reason(i);}

var PreviewPage = window.open('',&quot;Preview&quot;);

PreviewPage.document.open();
PreviewPage.document.writeln(&quot; Request Preview&quot;);
PreviewPage.document.writeln(&quot;Opinion:+RdOpinion+&quot;);
PreviewPage.document.writeln(&quot;Other:&quot;);
for (var i = 1 ; i <= 16 ; i++) {
PreviewPage.document.writeln(&quot;+Request_reason (i))+&quot;);}

PreviewPage.document.print();
PreviewPage.document.close();
}

</SCRIPT>

<input type=&quot;button&quot; value=&quot;Print&quot; onClick=&quot;PrintMyForm();&quot;>
 
sorry
function PrintMyForm() {
var Request_reason = new Array();
var RdOpinion = document.Form2.RdOpinion.value;
for (var i = 1 ; i <= 16 ; i++) {
Request_reason (i) = document.Form2.Request_reason(i);}

var PreviewPage = window.open('',&quot;Preview&quot;);

PreviewPage.document.open();
PreviewPage.document.writeln(&quot; Request Preview&quot;);
PreviewPage.document.writeln(&quot;Opinion:&quot; + RdOpinion);
PreviewPage.document.writeln(&quot;Other:&quot;);
for (var i = 1 ; i <= 16 ; i++) {
PreviewPage.document.writeln(Request_reason (i));}

PreviewPage.document.print();
PreviewPage.document.close();
}

 
You know, an alternative way to do things would be to put the menu inside a relative div and set the menu to invisible then do the print, then set the menu back to visible again.
 
how do i do that ???
thanks
 
Try:

function PrintMyForm()
{
var RdOpinion = document.Form2.RdOpinion.value;
var PreviewPage = window.open('',&quot;Preview&quot;);

PreviewPage.document.writeln(&quot;<html><body>&quot;);
PreviewPage.document.writeln(&quot; Request Preview&quot;);
PreviewPage.document.writeln(&quot;Opinion:&quot; + RdOpinion);
PreviewPage.document.writeln(&quot;Other:&quot;);

for (var elindex = 1;elindex <= 16;elindex++)
{
PreviewPage.document.writeln(document.Form2.Request_reason[elindex].value + '<br>');
}

PreviewPage.document.writeln(&quot;</body></html>&quot;);
PreviewPage.document.close();
PreviewPage.document.print();
}

If you read many of my posts, I DETEST the use of i as an index counter, and th TGML here converts all of those to italicized characters following, as well.
 
This should work in IE and Mozilla (aka NS6,7, etc...)
Include a <div></div> tag around your entire menu like so:

<div id=&quot;menu&quot; name=&quot;menu&quot;>your entire menu goes here</div>

Notice I gave it the name of &quot;menu&quot;

Change your button to the following code:
<input type=&quot;button&quot; value=&quot;Print&quot; onClick=&quot;printPage()&quot;>

and add this to the header:
<script>
<!--

function printPage() {
if(document.getElementById) {
document.getElementById('menu').style.display = &quot;none&quot;;
window.print();
document.getElementById('menu').style.display = &quot;block&quot;;
}
else { if(document.all){
document.all['menu'].style.display = &quot;none&quot;;
window.print();
document.all['menu'].style.display = &quot;block&quot;;
}}
}

//-->
</script>

The above code will readjust to page so it looks like the menu was never there. If you would like it to just hide the menu but leave blank space there, try this:


<script>
<!--

function printPage() {
if(document.getElementById) {
document.getElementById('menu').style.visibility = &quot;hidden&quot;;
window.print();
document.getElementById('menu').style.visibility = &quot;visible&quot;;
}
else { if(document.all){
document.all['menu'].style.visibility = &quot;hidden&quot;;
window.print();
document.all['menu'].style.visibility = &quot;visible&quot;;
}}
}

//-->
</script>
 
kevin, i get an error &quot;object required&quot;
trollacious, i havean error :object doesn't support this property or method. i guess it is &quot;PreviewPage.document.print();&quot;
thanks for your help. i am learning with both methods.
 
It's possible there is something else on your page named &quot;menu&quot;

Try changing the names like so:

<div id=&quot;hide_menu&quot; name=&quot;hide_menu&quot;>your entire menu goes here</div>


<script>
<!--

function printPage() {
if(document.getElementById) {
document.getElementById('hide_menu').style.display = &quot;none&quot;;
window.print();
document.getElementById('hide_menu').style.display = &quot;block&quot;;
}
else { if(document.all){
document.all['hide_menu'].style.display = &quot;none&quot;;
window.print();
document.all['hide_menu'].style.display = &quot;block&quot;;
}}
}

//-->
</script>


If that doesn't do it, could you specify what version of IE you have? If it is IE 5.5 or higher, then could you provide your source code because it should work.
 
thanks Kevin, it worked.
The only problem that is left is the url that showing up at the bottom of the page. I wonder if i can get rid of it. On my machine, i can change the settings of my browser but for the users , i don't know if it is possible to achieve that.
thanks again.
 
I've heard about methods of formatting stuff you send to the printer in Internet Explorer, but that's beyond what I know. Also, I have no idea if that gets rid of the URL at the bottom.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top