All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
HTML,Dont,give,credit,comes,directly,from,pag
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,486. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Click here to see a screenshot of this code!Mess Officer Management System (Sistem Pengurusan Mess Pegawai)
By Mohd Fauzi on 11/23

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

TEXTAREA Tag Printing Bug Fix.

Print
Email
 
VB icon
Submitted on: 4/10/2001 1:30:20 PM
By: Kevin Pirkl 
Level: Beginner
User Rating: By 2 Users
Compatibility:HTML, VbScript (browser/client side)

Users have accessed this code 14724 times.
 
author picture
(About the author)
 
     Dont give me any credit for this one comes directly from the pages of Microsoft. (http://msdn.microsoft.com/voices/webteam04022001.asp#topic2) If your page is going to be printed and it contain TEXTAREA tags that span multiple pages here is how you will print it.<BR> Getting Cut Short in Internet Explorer 5.5<BR> Dear Web Team, When I try to print a pretty large TEXTAREA (longer than one page) in IE 5.5 it gets cut off at the bottom of the first page! What gives? Thanks! Afi Hoboots The Web Team Replies: Wow, that's one big TEXTAREA! What you're running into here is a limitation of the new printing work in IE 5.5. Yes, the same code that brought you such hits as Print Preview and customizable Print Templates is unfortunately also responsible for the truncation of your longer-than-a-page TEXTAREAs. IE 5.5 is currently unable to break TEXTAREAs across multiple pages, but on the up side, there's a slick workaround! The basic workaround is to set up event handlers for the onbeforeprint and onafterprint events that substitute DIVs for the TEXTAREAs before printing occurs and remove them after printing is done, since DIVs can be broken across multiple pages. It gets a little tricky, though, because you need to substitute <BR> elements for the line breaks and add non-breaking spaces in order to preserve the formatting correctly. This is where we need to reach for the script developer's Swiss Army knife—regular expressions. What would normally have to be implemented in a clunky finite state machine can be done much faster using two simple regular expressions. Turning on the global search flag when substituting in a pair of   elements for every pair of spaces actually catches all combinations of spaces in one shot, since HTML always gives you one space for free. Once we've constructed the DIVs, we give them IDs based on the TEXTAREAs they're replacing (so we can find them again after printing and remove them) and insert them into the document using the insertBefore method. So after all that hype, here's the code:
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: TEXTAREA Tag Printing Bug Fix.
    ' Description:Dont give me any credit fo
    '     r this one comes directly from the pages
    '     of Microsoft. (http://msdn.microsoft.com
    '     /voices/webteam04022001.asp#topic2) If y
    '     our page is going to be printed and it c
    '     ontain TEXTAREA tags that span multiple 
    '     pages here is how you will print it.<
    '     BR>
    Getting Cut Short in Internet Explorer 5.5<BR>
    Dear Web Team,
    When I try To print a pretty large TEXTAREA (longer than one page) in IE 5.5 it gets cut off at the bottom of the first page! What gives?
    Thanks!
    Afi Hoboots
    The Web Team Replies:
    Wow, that's one big TEXTAREA! What you're running into here is a limitation of the new printing work in IE 5.5. Yes, the same code that brought you such hits as Print Preview and customizable Print Templates is unfortunately also responsible for the truncation of your longer-than-a-page TEXTAREAs. IE 5.5 is currently unable to break TEXTAREAs across multiple pages, but on the up side, there's a slick workaround!
    The basic workaround is To Set up Event handlers For the onbeforeprint and onafterprint events that substitute DIVs for the TEXTAREAs before printing occurs and remove them after printing is done, since DIVs can be broken across multiple pages. It gets a little tricky, though, because you need to substitute <BR> elements for the line breaks and ADD non-breaking spaces in order to preserve the formatting correctly. This is where we need to reach for the script developer's Swiss Army knife—regular expressions. What would normally have to be implemented in a clunky finite state machine can be done much faster using two simple regular expressions. Turning on the global search flag when substituting in a pair of   elements for every pair of spaces actually catches all combinations of spaces in one shot, since HTML always gives you one space for free. Once we've constructed the DIVs, we give them IDs based on the TEXTAREAs they're replacing (so we can find them again after printing and remove them) and insert them into the document using the insertBefore method. 
    So after all that hype, here's the code:
    ' By: Kevin Pirkl
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6584&lngWId=4    'for details.    '**************************************
    
    <HTML>
    <HEAD>
    <TITLE>IE 5.5 TEXTAREA Cropping Workaround</TITLE>
    </HEAD>
    <BODY onload="fillAreas();" onbeforeprint="subInDivs();" onafterprint="putBackTextAreas();">
    <SCRIPT LANGUAGE="JScript">
    function subInDivs() 
    {
    var collTextAreas = document.all.tags("TEXTAREA");
    var oNewDiv;
    var sTemp;
    var i;
    For (i = 0; i < collTextAreas.length; i++) 
    {
    oNewDiv = document.createElement("DIV");
    oNewDiv.style.width = collTextAreas(i).clientWidth;
    oNewDiv.style.height = collTextAreas(i).clientHeight;
    oNewDiv.id = collTextAreas(i).uniqueID + "_div";
    // replace all line breaks With HTML line breaks
    sTemp = collTextAreas(i).value.replace(/\n/gi,"<BR>"); 
    // match 2 spaces With To non-breaking spaces
    sTemp = sTemp.replace(/\s\s/gi,"  "); 
    oNewDiv.innerHTML = sTemp; 
    collTextAreas(i).parentNode.insertBefore(oNewDiv, collTextAreas(i));
    collTextAreas(i).style.display = "none";
    oNewDiv = null;
    }
    }
    function putBackTextAreas()
    {
    var collTextAreas = document.all.tags("TEXTAREA");
    var oDivToRemove;
    var i;
    For (i = 0; i < collTextAreas.length; i++) 
    {
    oDivToRemove = document.all(collTextAreas(i).uniqueID + "_div");
    if (oDivToRemove != null)
    {
    oDivToRemove.removeNode(true);
    }
    collTextAreas(i).style.display = "";
    }
    }
    function fillAreas() 
    {
    var sTempLine = "";
    var collTextAreas;
    var i;
    for(i = 0; i < 250; i++)
    {
    //build String
    sTempLine += "XXXXXXXXXXXXXXXXXXXXXXXXXX X XXX XX\n";
    }
    collTextAreas = document.all.tags("TEXTAREA");
    For (i = 0; i < collTextAreas.length; i++)
    {
    collTextAreas(i).value = sTempLine;
    }
    }
    </SCRIPT>
    <H2>IE 5.5 TEXTAREA Cropping Workaround</H2>
    <TEXTAREA ID="ta1" ROWS="253" COLS="70"></TEXTAREA>
    </BODY>
    </HTML>


Other 5 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
4/11/2003 9:16:30 AM

I really enjoy this article, but i still have one problem...
how can I print a text wich come from a textarea but the size of the textarea is minor than the text, so I have the scrollbars. when i print junt what i can see in the page is print the other part not..
(If this comment was disrespectful, please report it.)

 
4/11/2003 7:22:29 PMKevin Pirkl

I just noticed that the formatter that PSC is using is messing up the JavaScript "For"... It should be lower case "for"
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.