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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    document.write and page never finishes loading

    So I have an HTML page with javascript that takes input values, computes some results, and then puts these results in a table. Works great. Now I realize some users might want to print just the results table. So I add a button that allows the user to request the table in a separate window; clicking the button invokes a script to re-create the table in a separate window. Works fine except:

    * In the status bar, the window appears to never finish loading
    * If you go to File -> Print then nothing seems to happen; however,
    if you close the generated window _then_ the print dialog appears;
    the window you want to print, however, is gone.

    Any suggestions?

    The code invoked by clicking the newly added button:

    [CODE]
    function grabResults()
    {
    var w = window.open("","ROIResults"+winCount++,
    "height=400,width=600,menubar=yes");
    var d = w.document;
    d.write('<head>');
    d.write('<link href="style.css" title="compact" rel="stylesheet" type="text/css" />');
    d.write('<title>Return On Investment Calculations</title>');
    d.write('</head>');
    d.write('<body>');
    d.write('<div id="logoholder">');
    d.write(' <img src="TTFlogo2.gif" alt="Cannott display logo" "width="322" width="322" height="51"></p>');
    d.write('</div>');
    d.write('<div id="header">');
    d.write(' <h2>Return on Investment Estimator for Classroom Training</h2>');
    d.write('</div>');
    d.write('<table rules="all" frame="box">');
    d.write('<caption>Results - Estimated ROI</caption>');
    d.write(' <tr><th>Course</th>');
    d.write('<td class="center" id="courseName">'+cname+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Duration (Days)</th>');
    d.write('<td class="center" id="courseDur">'+cdays+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Class Size</th>');
    d.write('<td class="center" id="courseSize">'+csize+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Location</th>');
    d.write('<td class="center" id="courseLoc">'+teach_loc+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Training Cost</th>');
    d.write('<td class="justr" id="courseCost">'+TC+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Initial Value</th>');
    d.write('<td class="justr" id="courseInitial">'+startValue+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Returned Value</th>');
    d.write('<td class="justr" id="courseValue">'+RV+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Increase in Value</th>');
    d.write('<td class="justr" id="courseIncr">'+Inc+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>Net ROI after costs</th>');
    d.write('<td class="justr" id="courseROI">'+ROI+'</td>');
    d.write(' </tr>');
    d.write(' <tr><th>ROI Rate</th>');
    d.write('<td class="justr" id="courseROIRate">'+ROIR.toFixed(2)+'%</td>');
    d.write('</tr> '); */
    d.write('</table>');
    d.write('<p class="in3">(All amounts are in US Dollars.)</p>');
    d.write('</body>');
    d.write('</html>');

    d.close();
    return true;
    }

    [ICODE]
    Last edited by Steve Comstock; 11-21-2010 at 06:49 PM. Reason: Add prefix

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    document.write statements must be run before the page finishes loading. Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. So document.write is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,020
    Thanks
    15
    Thanked 239 Times in 239 Posts
    d.write('</tr> '); */ should be d.write('</tr> ');

    Fifth line from the bottom of the document write code.

  • Users who have thanked DrDOS for this post:

    Steve Comstock (11-21-2010)

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DrDOS View Post
    d.write('</tr> '); */ should be d.write('</tr> ');

    Fifth line from the bottom of the document write code.
    Yes, I just saw that, fixed it, and now it works! Thanks!


  •  

    Tags for this Thread

    Posting Permissions

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