Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print() method to just print <textarea>

Status
Not open for further replies.

Toastie

Programmer
May 19, 2001
123
AU
i have looked and cannot find the solution
i want to just print the textarea

<TEXTAREA NAME=&quot;Order&quot; ROWS=9 COLS=58 READONLY WRAP=OFF>YOU WISH TO ORDER THE FOLLOWING :</TEXTAREA>
<INPUT TYPE=button VALUE=Print NAME=PrintForm onclick=print()>

the trouble is i have lots of content and i only want to print the textarea and i over came this by opening a new window containing only the textarea contents and having a print button on that page

any clues
 
Here it is:

<form name=&quot;myform&quot;>
. . .
<INPUT TYPE=button VALUE=Print NAME=PrintForm onclick=printText(document.myform.order.value)>
</form>


Then place this in <head>:

<script>
function printText(content) {

w = window.open('','', 'location=no,scrollbars=no,menubar=no,toolbar=no,width=150,height=100');
w.document.open();
w.document.write('<html><body onload=&quot;print()&quot;>')
w.document.write(content);
w.document.write('</body></html>');
w.document.close();
}
</script>

This opens a popup window and writes the value of your textarea to it. Once a popup window is loaded, the standard [tt]print()[/tt] function is called that opens Print dialog.
 
sorry i should have explained myself a little more

thanks and that is exactly what i have done but with both of our methods the popup window dosent close for some reason after it prints
 
It doesn't close because there's no any action that should do it.
You can add [tt]close();[/tt] after printing but I think that the user is clever enough to click on [x] at the top right corner.
 
<script >
var valueTx='';

function printValutTx(valTx){
document.write(&quot;u re printing this value&quot;);
document.write(&quot;<textarea rows='8' cols='8' style='margin:0;border-top:0; border-left:0; border-right:0; border-bottom:0;overflow:hidden' >&quot;+valTx+&quot; </textarea>&quot;);
document.write(&quot;<input type='button' value='&lt;Back' onclick='history.go(-1)'/> &quot;);
// window.print();
}

</script>


<TEXTAREA NAME=&quot;Order&quot; ROWS='9' COLS='58' WRAP='ON'></TEXTAREA>
<INPUT TYPE='button' VALUE='Print' NAME='PrintForm' onclick='printValutTx(Order.value)'>
</textarea>
 
So in heinsight there is no real solution to my problem. The problem has been solved but I still feel our solution is inadequate.
Thems the brakes.
At least I can hope that in the next version of javascript they add more function to the print() method.

To all helpers everywhere including myself (because I try to be one) a pat on the back.
[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top