Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP jQuery
hi,
 
I am creating a form. and i want to take printout of the the form only.
When i use
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 12-Sep-12 20:12pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
Add a html page
<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
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('
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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>
 
  Permalink  
v2
Comments
Rajeshkrathor at 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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 883
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 166
4 ChauhanAjay 150
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100