Print Form Only Assistance

admin

Administrator
Staff member
After hours of searching th web and wandering off into a programming nightmare, I have returned yet once again to see if you brainiacis can be of anymore help to this little bitty hick. All I am trying to do is create a button that will print a form and not the entire page. I have tried the print command and it printed everything, I have attempted JavaScript <script language="JavaScript" type="text/javascript"><br />
if (window.print) { <br />
document.write('<form>' + '<input type=button span id="printtext" name=print value="Print" '+ 'onClick="javascript:window.print()"> </form>'); <br />
} <br />
</script><br />
and it too printed the entire window. From everything I have read it seems like my only possible solution is Pearl (which I am cheap and my website host doesn't support the POST method on the free accounts) which I have never touched and from what I have read looks like an ulcer waiting to happen. Or by previewing the form in a static html page prior to printing the content. Is there anyone who knows of anything I can read to fix this one little problem. I am trying to avoid programming as much as possible for JavaScript is about the extent to all the programming I hope I ever need to learn. I do not need an answer for I am a big boy. I just need a little direction towards the resources I need. I got a 12er (as always since I am a hick) in the fridge for the first runner up....heh Thanks.<!--content-->To print just partial contents of a page, you just set up a popup window as your print window; and then populate it with the content you want printed:<br />
<html><br />
<head><br />
<title>Untitled</title><br />
<script><br />
function printIt(target) { <br />
winId=window.open('','printwin','width=200,height=300'); <br />
winId.document.write(target); <br />
winId.document.close(); <br />
winId.focus(); <br />
if (window.print) winId.print();<br />
winId.close(); <br />
} <br />
</script><br />
</head><br />
<br />
<body><br />
<div id="div1"> <br />
<form><br />
field 1 <input type="text"><br><br />
field 2 <input type="text"><br><br />
field 3 <input type="text"><br><br />
field 4 <input type="text"><br><br />
field 5 <input type="text"><br><br />
</form><br />
</div><br />
<input type="button" value="Print Content" <br />
onClick="printIt(document.getElementById('div1').innerHTML);return false"><br />
</div><br />
</body><br />
</html><br />
<br />
Any tagging in the text sent to the new window will be preserved, and sent across to the printer. The popup could be used as a print preview by holding off the print command and getting a confirmations from the user before actually issuing the print command.<br />
<br />
IE and Mozilla<br />
<br />
<br />
A rare good use for a popup :D<!--content-->you can also set what you want printed in a div container and just have the css print that id of that div.<br />
<br />
why would perl be the solution as that is serverside. css has amny possibilities for printing.<!--content-->Thanks for the feedback you two. I am trying to avoid having the info pop up into a pop-up window if at all possible so I will have to find some stuff on the css possibility. Honestly the thought never even crossed my mind. Talk about a lon week...a week at the plant can do more brain damage then the alcohol I am drinking now.....time to get back to the old lady before I find myself sleepin on the couch again...lol<!--content-->You can do it with css this way:<br />
<br />
<style><br />
@media Print {<br />
.hideclass {display:none; }<br />
}<br />
</style><br />
<br />
The give everything you do not want printed a class of hideclass and they will not get printed... but it can be a lot of work if the page contains a lot of non-print elements, plus it is more difficult to maintain.<br />
<br />
Cd&<!--content-->
 
Back
Top