Results 1 to 14 of 14

Thread: How do I hide the button on the printed page?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665

    Question How do I hide the button on the printed page?

    How do I hide the button on the printed page. The button should only show on screen.
    Now I have done like this, but the button shows on the printed page.
    Code:
    <font class="size1" face="Arial" size="1"> 
    <input name="button2" type="button" value="PRINT OUT" onClick="window.print()" style="font-family: geneva,verdana; font-size: 8pt;"></font>

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I would change the onlclick to a function you write
    onlcick="printme()"
    then use

    function printme()
    {

    document.formname.button2.visible = false;
    window.print();
    }

    I think that should work fine.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    You can set the media in the style tag to use different stylesheets for different media, but I'm not sure how well this is supported yet.

    Code:
    <style type="text/css" title="Default" media="screen">
    ...
    </style>
    <style type="text/css" title="PrintCSS" media="print">
    ...
    </style>
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  4. #4
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    It's pretty well supported actually. The browsers I have all support it (Mozilla 1.2.1, Opera 6.05, IE 6). I would go with the meda thing too, it's easier and better supported for people with out JS.

    Also you could do (including the code you want)

    <style media="all" type="text/css">
    @media print {
    input { display: none }
    }
    </style>

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks everybody!

    But, can you show a complete code with a button included.

    I would be greateful for that.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Someone...

  7. #7
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Put what I said in the head of the document and it should work:

    Code:
    <head>
      <style media="all" type="text/css"><!--
      @media print {
        input { display: none }
      }
      --></style>
    </head>
    That will hide all inputs. You could change input for form if you don't want any of the form showing, or any other element.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks Rick Bull,

    Now it works!
    But I have another following question.
    I wanna hide all buttons when I print out. But I also want to hide a part of the text when I print out. How do I do then?

  9. #9
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Well one way of doing it is to add to the style like this:

    Code:
    <head>
      <style media="all" type="text/css"><!--
      @media print {
        .hide, input { display: none }
      }
      --></style>
    </head>
    then if you want to comment out text within a paragraph or other block element just add a span with a class of hide like so:

    Code:
    <p>Some of this text will be <span class="hide">hidden</span>.</p>
    Or if you want to hide an entire block:

    Code:
    <p class="hide">All of this text will be hidden.</p>

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    That was exactly what I need, Rick Bull. Thanks!

    Another question,

    If I wanna hide all buttons and all text on print out except for the table? How do I do then?
    Here is an example on a table code which I mean:
    Code:
     
    <TABLE cellSpacing=% cellPadding=1 width=440 border=6><B>
      <CAPTION>
      <DIV><FONT size=4>Here I write the Caption</FONT></DIV>
      <DIV><FONT size=4></FONT>&nbsp;</DIV></CAPTION></B>
      <TBODY>
      <TR>
        <TH align=middle bgColor=#cfcfcf>Pierre</TH>
        <TH align=middle bgColor=#cfcfcf>Carol</TH>
        <TH align=middle bgColor=#cfcfcf>Greg</TH>
      <TR>
        <TD align=middle>Jan </TD>
        <TD align=middle>Alice </TD>
        <TD align=middle>Peter&nbsp;&nbsp;</TD>
      <TR>
        <TD align=middle>Cindy </TD>
        <TD align=middle>Mike </TD>
        <TD align=middle>
    
    
       </TR></TBODY></TABLE>
    And here is my last question,

    When I print the current code here abowe, no bgcolors are used? How do I solve that?
    Last edited by Pirre001; Jan 19th, 2003 at 04:33 PM.

  11. #11
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Well without seeing your code in action, I would just place a DIV around the text you want to hide, and give it class of hide:

    Code:
    <div class="hide">
      <p>Hidden text and stuff goes here</p>
      <form><p>
        <input /> etc.
      </p></form>
    </div>
    
    <table>
       ...
    </table>
    
    <div class="hide">
      Anything else afterward that you want hidden
    </div>
    As for the colours I'm not sure, but I've heard of people having problems when printing. The only things I could say are make sure your printer settings are correct when you press print (e.g. make sure you are printing in colour mode and not black and white), or try using style instead:

    Code:
    <TH align=middle style="background-color: #cfcfcf;">Pierre</TH>

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks again!

    But I still have problem with the background color when I'm printing. Do you have any other solution?

    And do you know if I could use this code in a HTML-mail with Microsoft Outlook?

  13. #13
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Sorry I'm not sure why the colour isn't working. Maybe it's a bug, like I say I've seen other people with the problem.

    If you can edit the source in Outlook then you should be able to use the code, but how well supported it is in Mail clients I have no idea. I know it will work perfectly in Mozilla's mail client, but that's all I know I think CSS support is a bit patchey in some mail clients.

  14. #14
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    But I still have problem with the background color when I'm printing
    I dont think background colours are printed along with the page.
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width