-1

I want to know how to print following table from my database. This is its form when showed on the browser.

I want to print this table, and I'm confused because I made a print button, but when I press it, it prints the whole webpage.

How can I print only the table?

DATE:   ||AMOUNT:

2013   || 2000

2013   || 200

2013   || 2000

2013   || 2000

TOTAL AMOUNT PAID:  6200

TOTAL TUITION:    9000

REMAINING BALANCE:  2800
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Anna Mae
  • 95
  • 1
  • 10

2 Answers2

1
<div id="printableArea">
      // wrap your content within this div
      DATE:   ||AMOUNT:

      2013   || 2000

      2013   || 200

      2013   || 2000

      2013   || 2000

      TOTAL AMOUNT PAID:  6200

      TOTAL TUITION:    9000

      REMAINING BALANCE:  2800
</div>

<input type="button" onclick="printDiv('printableArea')" value="Print" />

And the button click javascript

function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

Source : One of SO Solution

Community
  • 1
  • 1
asprin
  • 9,579
  • 12
  • 66
  • 119
0

You will need to as tradyblix said in their comment, create a page with just the table on it. You can have a button that takes you to that page.

In that page, you can have javascript automatically print it.. To do that in the head put this in

<script language="javascript" type="text/javascript">
function print_page() {
  window.print();
}
</script>

And on the body tag

<body onload="print_page()">
chip
  • 599
  • 1
  • 9
  • 20