PDA

View Full Version : printing textarea



Janos Ban
Jun 1st, 2007, 02:24 PM
How can I print only a textarea of a page (not the whole page)? Thanks

rwedge
Jun 1st, 2007, 03:27 PM
Here is an example of printing just the contents of a textarea:
<script type="text/javascript">
/*<![CDATA[*/
function pwin(tarea,width,height) {
myfloater=window.open('','Page_Title','scrollbars=yes,toolbar=no,resizable=yes,status=no,width='+wid th+',height='+height+',top='+((screen.availHeight/2)-(height/2))+',left='+((screen.availWidth/2)-(width/2))+',directores=no');
myfloater.document.open();
myfloater.document.write(tarea);
myfloater.document.close();
myfloater.focus();
myfloater.window.print();
}
/*]]>*/
</script>

<form id="myform" method="post" action="" enctype="multipart/form-data">
<textarea id="print_area" cols="70" rows="30"></textarea><br />
<input type="button" id=".buttom" value="Print" onclick="pwin(form.print_area.value,500,400)" />
</form>

glenngv
Jun 1st, 2007, 05:58 PM
There's a way to print without opening a new window.

http://www.codingforums.com/showthread.php?t=35969#post187386

Janos Ban
Jun 5th, 2007, 11:30 AM
Thanks, I'm sorry but I have to correct my question. I've a textarea on a page, the lines of the area would be arbitrary much. I need a method for printing all of lines or a part of lines (For example I let print with it a single line too. )

glenngv
Jun 5th, 2007, 04:02 PM
You can still use the code in the link I posted. You just need to modify it a bit to exactly suit your needs. You need to split the textarea content and get the desired line. Here's a sample code on how to split the textarea content.

var lines = textareaElement.value.split(/\n|\r\n/g);
for (var i=0; i<lines.length; i++){
alert(lines[i]);
}