1 reply [Last post]
Last seen: 18 years 18 weeks ago
Joined: 2004-08-03
Posts: 6
Points: 0

I'm looking for some help with a snippet of code for the site I'm working on, I need a print form button. I've got it printing the page, but I'm unsure how to 'convince' it to print the form only, leaving the rest of the page untouched.

Here's a snip of my code:

<SCRIPT Language="Javascript">

function printit(){
if (window.print) {
window.print() ;
} else {
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
</script><SCRIPT Language="Javascript">
var NS = (navigator.appName == "Netscape");
var VERSION = parseInt(navigator.appVersion);
if (VERSION > 3) {
document.write('<form><input type=button value="Print" name="Print" onClick="printit()"></form>');

Thanks for everything.

safull's picture
Madrid -Spain
Last seen: 19 years 14 weeks ago
Madrid -Spain
Timezone: GMT+1
Joined: 2003-08-27
Posts: 17
Points: 0

Print Form Javascript

¿You just want to print only the formulary?
You could use a Css file applied only in the print media.


<div class="noPrint">Some cool text, html o whatever, but no printed</div>
<form name="IWillBePrinted">
//more formulary elements inputs

You can also do it reverse, thats a class that indicates printing, or make all unprinted and redefine the forms elements display(inline,block,list-item). Maybe more complex.