Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,

I am creating a form. and i want to take printout of the the form only.
When i use
HTML
window.print()

it take whole page for print.

i want is there any code so that i can take only the selected portion of the form.

thanks
Posted

Try this

<html>
<head>

<script type="text/javascript">

function CallPrint()
   {
    
    // getting content from previous window
    //var prtContent = document.getElementById( strid );
    // here your are opening a new window with custom size
    var WinPrint = window.open('', '', 

'left=30,top=0,width=600,height=600,toolbar=1,scrollbars=1,status=0');
    var ss='<table style="text-align:justify;"><tr><td><style type="text/css">your styles</style><h1>ITS A TEST......</h1><br /><h1>ITS A TEST</h1><br /><br /><h1>CONTENT FOR PRINTING.........</h1><br /></td><table><tbody><tr></tr></tbody></table></tr></table>';
    // preparing page content 
    WinPrint.document.write(ss);
    // writing that content to new window
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
   }

</script>

</head>

<body>

<br />
<br />
<br />

<a  önclick="CallPrint()">PRINT</a>

</body>

</html>
 
Share this answer
 
v2
Comments
[no name] 13-Sep-12 4:27am    
Thanks vino2012

Its working but my Question was, i want to print a form.
you creating a form in <script> then printing it but i want to print form which is in <body>.

Thanks
Hi,
Add a html page
HTML
<head>
<script language="javascript" type="text/javascript" src="print_part_page.js"></script>
</script></head>
<body>
<p id="printout" style="font-size:150%">This part of page will be printed!</p>
<p style="font-size:150%"><a href="#" onclick="var obj = new printPartOfPage(); obj.printPart('printout');">Click to print a part of page</a></p>

</body>


here is the print_part_page.js
JavaScript
var wi = null;
printPartOfPage = function(){
				
					if( wi && (!wi.closed ) )
					  {
						  wi.close();
					  }
					  
					this.printPart = function(divId)
									{
						  
										html = document.getElementById(''+divId+'').innerHTML;
										
										wi=window.open('','printingpage');
										
										wi.document.write('
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900