views:

336

answers:

3

I am trying to print a page using javascript, it works fine but the issue comes with a page havign form inside it. If we print the form values being printed are fine but what we get is html controls (like input ,dropdown) are also being printed. Can some one have any other idea except server side processing

+7  A: 

You can attach a print stylesheet to your pages like so...

<link rel="stylesheet" href="print.css" media="print"/>

Then in the print stylesheet you can specify...

input, select
{
    display: none;
}

This will hide your form control elements but only when the page is printed. You can extend this by also hiding navigation and links i.e. anything that is not useful on a printed version of your web page

EDIT: As rightly pointed out if you want to still display values within textboxes etc you can set the border-style property to "none" (+ any style declarations that you see fit) and only hide elements that serve no purpose when printed such as buttons

Nick Allen - Tungle139
This will also hide the value in the control. Did you need the value to be visible, but the control to be hidden?
rikh
But the idea is valid. simply set the border-style:none instead of of display:none in the printed version for inputs that you want to print the value of, and set the display:none only for buttons etc that you want to hide.
Vincent Ramdhanie
yeah i know the css idea but setting the border is a clever trick i will check this,
Gripsoft
A: 

You can provide different css for print and screen display.

In your print css you can probably get rid of most of the html controls visible parts by setting borders to nothing, background to white and so on. I have not tried getting rid of everything this way though, so you may still end up with the odd bit. Worth a try though.

rikh
A: 

Yes. You'll have to define a different CSS style that will support media="print". CSS intended for print will hide appropriate controls and display static fields.

Robert Koritnik