51 users online (0 members and 51 guests)  


  Results 1 to 7 of 7

Related

  1. How to set value to a TEXTAREA ?    Forum: Javascript Forum
    Replies: 1
  2. Limited Textarea    Forum: HTML Forum
    Replies: 4
  3. CSS Print    Forum: CSS Forum
    Replies: 2
  4. Textarea or something    Forum: HTML Forum
    Replies: 2
  1. #1
    woodknut's Avatar
    Disabled

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    32

    How do you print content of textarea?

    I have a "Terms & Conditions" textarea defined on a page and would like to add a button for printing the content of the textarea. Something like this:

    <INPUT type="button" value=" Print Terms " onClick="printTerms( document.termsService )">

    where termsService is the name of the textarea.
    It looks like window.print() doesn't take arguements and will print the entire window. I'm not keen on printing from a popup at this point in time.

    What "method" can be used to print the content of the textarea once passed to the function called printTerms()?
    Assuming I'm passing it correctly ;-)

    W.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Good question.

    Directly, printer access is very limited from the web (I think they fear a new wave of spam that just keeps coming out of your printer ) but one thing you can do is to specify an alternate document for printing when a print call is asked for. Its a <link> and looks like -

    Code:
    <link rel="alternate" media="print" href="termsandconditions.html">
    This will work. However, the (big) drawback is that it only works in Internet Explorer.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    woodknut's Avatar
    Disabled

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    32
    Actually "printer spam" is one of our concerns. Don't want to rile our users any more than necessary

    Thanks for the "alternate" choice. Our web stats show that IE is overwhelming the browser of choice though I would prefer to have as much cross-browser availability as possible (with as little coding as possible).

    hmmm...
    Let ya know what I end up doing.
    W.

  4. #4
    Enigma's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Nov 2000
    Posts
    426
    Does this help any?

    http://groups.yahoo.com/group/cold_fusion/message/4490

  5. #5
    woodknut's Avatar
    Disabled

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    32
    Enigma,
    Thanks, I ran across that code snippet on another site. While its not the most elegant it will work for me.

    Since the window.print() function prints the "current" window, is there a way to print the "child" window?

    winId = window.open('','newwin');

    winId.print() ?

    so that I could make the function call from the main window?

    W.

  6. #6
    woodknut's Avatar
    Disabled

    Status
    Offline
    Join Date
    Dec 2003
    Posts
    32
    Survey says....YES!
    Here's how I did it:

    Main page snippets:

    <SCRIPT LANGUAGE="JavaScript" src="popup.js"></script>
    <SCRIPT LANGUAGE="JavaScript" src="tools.js"></script>
    ...
    ...
    <INPUT type="button" value=" Print Terms " onClick="printTerms('termsOfService.html')">


    popup.js :
    function popup(URL) {
    var winRef;
    day = new Date();
    id = day.getTime();
    winRef = eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=350,left = 50,top = 10');");
    return winRef;
    }

    tools.js:
    function printTerms(URL) {
    var winRef;
    winRef = popup5( URL );
    winRef.print();
    }


    Mind you the eval() portion of the popup is a vestige of previous coding. Oddly enough if I remove it I get an error on page.

    Any critique is gladly welcomed.
    W.

  7. #7
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Thats a pretty nice bit of code. Thanks for coming back and letting us know.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread