user2962142 user2962142 - 1 year ago 61
HTML Question

How can I insert a Print button that prints a form in a webpage

So, lets say I got a simple form inside a page like this:

<form style="text-align:center;">
<p> STUFF </p>

I wanna add a button so when the user clicks on it the browser's Print dialog shows up, how can I do that?

Edit: I wanna print the form, not the page.

Answer Source

Try adding a button that calls window.print()

<input type="button" value="Print this page" onClick="window.print()">

For specific area of a page

<div id="print-content">

  <input type="button" onclick="printDiv('print-content')" value="print a div!"/>

then in HTML file add this script code

<script type="text/javascript">

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

Refer Print <div id=printarea></div> only?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download