Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript window.print(); Question

    Hello. I've written a Fax Cover Sheet generator web page for the company I work for. The user inputs all the information into a form and clicks 'print'. I do not know CGI, so i've accomplished the tasking using javascript to generate a pop-up window containing the formatted information from the form. However, no matter what I try, I can't get the browser to print the pop-up box instead of the main window. Can someone help me?

    Here is sample code that imitates how the real page works:

    **********************************************
    <html>
    <head>
    <title>Print Test</title>

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function displayHTML(form) {
    var notes = form.notes.value;
    var print = window.print();

    win = window.open(", ", 'popup', 'toolbar = no, status = no');
    win.document.write("<h1>" + notes + "</h1>");
    win.document.write("<SCRIPT LANGUAGE='JavaScript'>" + print + ";</script>");

    }
    // End -->
    </script>

    </head>

    <body>

    <form>
    <textarea cols=50 rows=10 name="notes"></textarea><br>
    <input type="button" value=" Print " onclick="displayHTML(this.form)">
    </form>

    </body>
    </html>

    ********************************************

    I would like the browser to print the resulting pop-up instead of the page where the user types in the information.

    Can anyone tell me how to accomplish this?

    Thanks in advance,
    -Shein

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the response, but that article shows how to open a different HTML document in a new window and have it print. The code I posted does not open a separate HTML document (with a different name than the referring page), but instead formats and creates its own pop-up window that needs to be printed.

    I would be happy to call a new html page and have that print if I could work out a way of carrying over the form information from the original page...


    Thanks for any advice/help you can provide.


    EDIT: Here is a link to the actual page i'm designing if that helps

    http://www.metrolightingcenters.com/...coverwhite.htm






    .
    Last edited by SheinTao; 01-27-2006 at 08:54 PM.

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Why open a new window? You could just do something like this:

    Code:
    <html>
    <head>
    <title>Print Test</title>
    
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function printPage(form) 
    {
    	document.getElementById('printable').innerHTML='<h1>'+form.elements['notes'].value+'</h1>';
    	form.style.display='none';
    	window.print();
    	document.getElementById('printable').innerHTML+='<input type="button" onclick="showForm();" value="Again?" />';
    }
    function showForm()
    {
    	document.forms[0].reset();
    	document.getElementById('printable').innerHTML='';
    	document.getElementById('form1').style.display='block';
    }
    // End -->
    </script>
    
    </head>
    
    <body>
    
    <form id="form1">
    	<textarea cols=50 rows=10 name="notes"></textarea><br>
    	<input type="button" value=" Print " onclick="printPage(this.form);return false;">
    </form>
    <div id="printable">
    </div>
    
    </body>
    </html>
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #5
    New Coder
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Basscyst, that's great! Thank you!

    I used your example and got the print working perfectly

    However, I can no longer figure out how to get the "Select Paper Type" drop-down navigation box to work. I can make it work if I put a new form outside of "form1", but then it gets printed on the cover sheet. What am I doing wrong here?

    http://www.metrolightingcenters.com/MLHelper/test.htm


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •