1

I want to use jquery to print and here i have a button to perform this taxk but I want this to be printed after the form submission.

here is my code that prints the content on button click event, after printing ti will submit the form.. how can i do this..

<button  id="btnjson" type="submit" value="ok" class="button" onclick="printDiv('print-table')">Ok</button>



<script>
function printDiv(divName) {
 //alert('s');
 var printContents = '<div id="print-content"><form><table width="100%"  height="100" ><tbody >';
  var inputs, index;
inputs = document.querySelectorAll('input,select');
printContents+='<div style="width:765px; float:left; height:72px;">'
printContents +='</tbody></table>';
 w=window.open();
 w.document.write(printContents);
 w.print();
 w.close();
}
</script>

3 Answers3

1

You can do in 2 ways.

1- can generate a screenshot using canvas

2- you may use jquery to hide elements and get print done before form submission

Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
1

How I did for printing invoices after successful response from backend is follows:

var mywindow = window.open('_blank', '', '');
mywindow.document.write('<html><head></head><body onload="setTimeout(myFunction(){window.print();}, 3000)">');  
var printContents = '<style>@media print {  .print_hide{display: none;} } </style>';
printContents += '<div id="print-content"><form><table width="100%" height="100"><tbody>';
var inputs, index; inputs = document.querySelectorAll('input,select'); 
printContents+='<div style="width:765px; float:left; height:72px;">';
printContents +='</tbody></table>';
mywindow.document.write(printContents);
mywindow.document.write('</body></html>');                        
mywindow.document.close();

It will open a new window...

WC2
  • 317
  • 1
  • 9
0

Nothing can be printed after job submission, you may have to send the data to be back-end and store it and then retrieve it. Using Session scope variables etc.

yeppe
  • 679
  • 1
  • 11
  • 43