How to print text from textarea?

I want to print text from a text area.

I have a text box whose text can be updated by the user. When the user updates the text from the text box, and then prints the updated text, you can print on the page. And this text can be printed on a print page without a text field.

Please suggest any solution.

thank

+5
source share
1 answer

I think I got what you ask for. Try:

<html>
  <head>
    <title>Print TextArea</title>
    <script type="text/javascript">
      function printTextArea() {
        childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes');
        childWindow.document.open();
        childWindow.document.write('<html><head></head><body>');
        childWindow.document.write(document.getElementById('targetTextArea').value.replace(/\n/gi,'<br>'));
        childWindow.document.write('</body></html>');
        childWindow.print();
        childWindow.document.close();
        childWindow.close();
      }
    </script>
  </head>
  <body>
    <textarea rows="20" cols="50" id="targetTextArea">
      TextArea value...
    </textarea>
    <input type="button" onclick="printTextArea()" value="Print Text"/>
  </body>
</html>

Basically, this will open another child window and print to JavaScript so that the text area and other things don't print.

+15
source

All Articles