printing all text from a textarea

  • mikeshane
  • Novice
  • Novice
  • mikeshane
  • Posts: 16

Post 3+ Months Ago

Hi,

I've got this textarea, which will be filled with data by the user. Only 3 lines of text are visible on the screen (textarea with 3 lines), but there are more lines of text entered by the user. Printing the page results in only 3 lines of text. How do I print <b>all</b> entered text of the textarea automatically ?

Thnx, Steve
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • pbrasilbr_brasil
  • Novice
  • Novice
  • pbrasilbr_brasil
  • Posts: 18
  • Loc: Brazil

Post 3+ Months Ago

Well
Have you checked your textarea size
maybe you have set the textarea to three lines only...and so, only those three lines will be visible...and the browser will print what you can see. And what you can see are those three lines(wow,what a confusion i made :shock: )
Well...i tried to help,heh. I hope you understood me...
Here's my textarea code...maybe it helps u
<textarea name="sugestoes" cols="50" rows="4" class="escrever-small-bold">

See...there are only 4 rows (four lines).
As i will receive what is on this textarea by e-mail, i don't worry about the size,heh...

Thats it. Hope it helps
Bye =)
Pablo.
  • the_Maven
  • Graduate
  • Graduate
  • the_Maven
  • Posts: 196

Post 3+ Months Ago

Heres another alternative using javascript, maybe:

<textarea name="sometext" cols="50" rows="5">
<input type="button" value="Print" onclick="javascript:print(sometext.value)">

that code will probably return an error, but you can see what i am getting at. it would then print the entire contents of the textbox, regardless of how many rows are visible.
i hope that is a push in the right direction.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

If you have a lot of text I think the only way you can do it is by popping up a window and writing the contents of the textarea to it, replacing the newlines with <br> and then printing the contents of the child window. Of course, a lot of people don't like popups and have blockers installed. but the better ones like the Google toolbar or Mozilla/Netscape's built-in bocker only block unrequested popups rather than those caused by clicking on a link or whatever.

Code: [ Select ]
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function printField() {
    var s = document.theForm.ta.value;
    var regExp=/\n/gi;
    s = s.replace(regExp,'<br>');
    pWin = window.open('','pWin','location=yes, menubar=yes, toolbar=yes');
    pWin.document.open();
    pWin.document.write('<html><head></head><body>');
    pWin.document.write(s);
    pWin.document.write('</body></html>');
    pWin.print();
    pWin.document.close();
    pWin.close();
}
</script>
</head>
<body>
<form name="theForm" action="">
<textarea name="ta" rows="20" cols="50">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut lorem enim, varius non, luctus sit amet, pellentesque at, eros. Aliquam odio neque, auctor in, fringilla vitae, porttitor nec, purus. Aliquam non ipsum. Aliquam ut est sed ante egestas vestibulum. Mauris ultricies consectetuer ligula. Nunc aliquet quam quis odio. Proin nonummy tortor et elit. Sed sem risus, pretium non, malesuada et, sollicitudin vel, purus. Nullam venenatis. Phasellus feugiat vulputate magna.

Sed nec mauris. Etiam ac arcu. Proin dolor dolor, tempor vel, iaculis in, fermentum molestie, augue. Sed eget pede sit amet mi semper varius. Ut vestibulum turpis a sem. Suspendisse faucibus sem nec lacus. Praesent mauris wisi, nonummy at, porttitor id, sodales quis, nulla. Vivamus vel est dapibus ipsum viverra interdum. Nam auctor est et nunc. Praesent turpis. Mauris sed ante et felis commodo iaculis. Phasellus risus augue, interdum eget, porta at, lacinia non, velit.

Suspendisse potenti. Maecenas a eros id quam luctus sodales. Curabitur elementum ligula in libero. In libero lorem, blandit eget, tempor placerat, accumsan vel, quam. Pellentesque nisl. Quisque vestibulum leo sit amet sapien. Morbi at massa. Duis purus sapien, laoreet sed, laoreet sit amet, nonummy non, justo. Duis felis nibh, euismod vulputate, pretium id, venenatis nec, justo. Integer laoreet ligula in diam. Donec porta consequat lorem. Curabitur eu nisl vitae dolor molestie mattis.

Vestibulum tincidunt, dolor sed feugiat aliquam, erat libero vestibulum lectus, eget molestie velit est eget ligula. Nam purus. In hac habitasse platea dictumst. Etiam pretium fringilla nibh. Pellentesque lectus metus, pharetra nec, molestie a, viverra vitae, diam. Sed ultrices est non mi aliquam dictum. Duis ullamcorper dolor vitae lorem adipiscing lobortis. Proin vel metus a lectus varius viverra. Quisque at odio. Suspendisse pede felis, dictum in, volutpat eu, tempus sollicitudin, pede. Quisque sit amet metus.

Pellentesque et mauris. In hac habitasse platea dictumst. Nunc rhoncus, diam eu posuere mollis, elit ligula euismod leo, eget gravida neque quam sit amet nibh. Mauris ac diam. Morbi tincidunt vestibulum mauris. Vivamus venenatis nonummy arcu. Suspendisse potenti. Donec nonummy tortor vitae pede. Aenean tempus. Ut dignissim, arcu quis vehicula venenatis, wisi nibh gravida magna, ut mollis est libero vitae libero. Fusce at felis. Maecenas vitae augue. Proin egestas magna vitae elit. Aliquam eros. Nulla a felis. In convallis wisi id quam. Fusce mattis.
</textarea>
</form>
<a href="#" onclick="printField()">print text</a>
</body>
</html>
  1. <html>
  2. <head>
  3. <title>Untitled</title>
  4. <script type="text/javascript">
  5. function printField() {
  6.     var s = document.theForm.ta.value;
  7.     var regExp=/\n/gi;
  8.     s = s.replace(regExp,'<br>');
  9.     pWin = window.open('','pWin','location=yes, menubar=yes, toolbar=yes');
  10.     pWin.document.open();
  11.     pWin.document.write('<html><head></head><body>');
  12.     pWin.document.write(s);
  13.     pWin.document.write('</body></html>');
  14.     pWin.print();
  15.     pWin.document.close();
  16.     pWin.close();
  17. }
  18. </script>
  19. </head>
  20. <body>
  21. <form name="theForm" action="">
  22. <textarea name="ta" rows="20" cols="50">
  23. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut lorem enim, varius non, luctus sit amet, pellentesque at, eros. Aliquam odio neque, auctor in, fringilla vitae, porttitor nec, purus. Aliquam non ipsum. Aliquam ut est sed ante egestas vestibulum. Mauris ultricies consectetuer ligula. Nunc aliquet quam quis odio. Proin nonummy tortor et elit. Sed sem risus, pretium non, malesuada et, sollicitudin vel, purus. Nullam venenatis. Phasellus feugiat vulputate magna.
  24. Sed nec mauris. Etiam ac arcu. Proin dolor dolor, tempor vel, iaculis in, fermentum molestie, augue. Sed eget pede sit amet mi semper varius. Ut vestibulum turpis a sem. Suspendisse faucibus sem nec lacus. Praesent mauris wisi, nonummy at, porttitor id, sodales quis, nulla. Vivamus vel est dapibus ipsum viverra interdum. Nam auctor est et nunc. Praesent turpis. Mauris sed ante et felis commodo iaculis. Phasellus risus augue, interdum eget, porta at, lacinia non, velit.
  25. Suspendisse potenti. Maecenas a eros id quam luctus sodales. Curabitur elementum ligula in libero. In libero lorem, blandit eget, tempor placerat, accumsan vel, quam. Pellentesque nisl. Quisque vestibulum leo sit amet sapien. Morbi at massa. Duis purus sapien, laoreet sed, laoreet sit amet, nonummy non, justo. Duis felis nibh, euismod vulputate, pretium id, venenatis nec, justo. Integer laoreet ligula in diam. Donec porta consequat lorem. Curabitur eu nisl vitae dolor molestie mattis.
  26. Vestibulum tincidunt, dolor sed feugiat aliquam, erat libero vestibulum lectus, eget molestie velit est eget ligula. Nam purus. In hac habitasse platea dictumst. Etiam pretium fringilla nibh. Pellentesque lectus metus, pharetra nec, molestie a, viverra vitae, diam. Sed ultrices est non mi aliquam dictum. Duis ullamcorper dolor vitae lorem adipiscing lobortis. Proin vel metus a lectus varius viverra. Quisque at odio. Suspendisse pede felis, dictum in, volutpat eu, tempus sollicitudin, pede. Quisque sit amet metus.
  27. Pellentesque et mauris. In hac habitasse platea dictumst. Nunc rhoncus, diam eu posuere mollis, elit ligula euismod leo, eget gravida neque quam sit amet nibh. Mauris ac diam. Morbi tincidunt vestibulum mauris. Vivamus venenatis nonummy arcu. Suspendisse potenti. Donec nonummy tortor vitae pede. Aenean tempus. Ut dignissim, arcu quis vehicula venenatis, wisi nibh gravida magna, ut mollis est libero vitae libero. Fusce at felis. Maecenas vitae augue. Proin egestas magna vitae elit. Aliquam eros. Nulla a felis. In convallis wisi id quam. Fusce mattis.
  28. </textarea>
  29. </form>
  30. <a href="#" onclick="printField()">print text</a>
  31. </body>
  32. </html>
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Hmm, opera doesn't seem to support window.print(). It might be a better idea to comment out or remove the last line of the script pWin.close() so that the window will stay open and opera users can print it manually.
  • CazpianXI
  • Proficient
  • Proficient
  • User avatar
  • Posts: 285

Post 3+ Months Ago

Why don't do something like this:

Code: [ Select ]
<script language="JavaScript">
<!--
function printerfriendly() {
  childWin = open("", "childWin",

"toolbar,scrollbars,menubar,status,innerwidth=300,innerheight=200");


  var text = document.theform.text.value;
  childWin.document.write("<p><b>You may print the text below for

your records:</b></p>");
  childWin.document.write(text);
}
</script>

<form name="theform" action="">
<textarea name="text" rows="20" cols="50">
Text goes here. Text goes here. Text goes here. Text goes here. Text

goes here. Text goes here. Text goes here.
</textarea>
</form>
<a href="#" onclick="printerfriendly()">Click here for a

printer-friendly version of the above text</a>
  1. <script language="JavaScript">
  2. <!--
  3. function printerfriendly() {
  4.   childWin = open("", "childWin",
  5. "toolbar,scrollbars,menubar,status,innerwidth=300,innerheight=200");
  6.   var text = document.theform.text.value;
  7.   childWin.document.write("<p><b>You may print the text below for
  8. your records:</b></p>");
  9.   childWin.document.write(text);
  10. }
  11. </script>
  12. <form name="theform" action="">
  13. <textarea name="text" rows="20" cols="50">
  14. Text goes here. Text goes here. Text goes here. Text goes here. Text
  15. goes here. Text goes here. Text goes here.
  16. </textarea>
  17. </form>
  18. <a href="#" onclick="printerfriendly()">Click here for a
  19. printer-friendly version of the above text</a>


This will open a new window and insert the value of the textarea inside of the new window. Then the user can print the text himself. This way, you can work around the browser problems.
  • CazpianXI
  • Proficient
  • Proficient
  • User avatar
  • Posts: 285

Post 3+ Months Ago

EDIT: I edited the above code, it had a bug. :oops:

Forgot to test it in Netscpape before posting it...
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Yes, you could do it that way and let the person print it manually. I really should have tested for the window.print() before calling it anyway - if(window.print) pWin.print(); - that way if printing from javascript is supported the user would be prompted with a print dialogue, and if it isn't then it would be up to them to print it, so closing it from the parent window probably wasn't a bright idea on my part. Either way I would replace the newlines in the textarea with br's to preserve them.
  • CazpianXI
  • Proficient
  • Proficient
  • User avatar
  • Posts: 285

Post 3+ Months Ago

Yes, RichB I think that you hit the nail right on the head! A comprimise between our two scripts would would work out the best.

mikeshane: If you can compile these two scripts, then great! If you need help, just reply to this post.

"Two heads are better than one" --who said that?

~ Cazpian the 11th
  • mailajayck
  • Born
  • Born
  • mailajayck
  • Posts: 3

Post 3+ Months Ago

I also face the same problem as mikeshane posted

can someone assist with the solution on how to approach
  • mailajayck
  • Born
  • Born
  • mailajayck
  • Posts: 3

Post 3+ Months Ago

I would need help to compile these two scripts together

Looks like I am close to the solution here!!! :)


CazpianXI wrote:
Yes, RichB I think that you hit the nail right on the head! A comprimise between our two scripts would would work out the best.

mikeshane: If you can compile these two scripts, then great! If you need help, just reply to this post.

"Two heads are better than one" --who said that?

~ Cazpian the 11th

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 61 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.