Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to control format of text output from a script

Status
Not open for further replies.

TexasEngineer

Technical User
Jan 27, 2007
1
US
I'm using a script (Javascript 1.2) to display the current date on a page I'm building. The text is output to the page using document.write ( ); in the script.

The resulting text however changes size when the browser settings change. In IE 6.0 View-Text Size-Smallest....or Medium or Largest, etc.

I've got other text on my page that is controlled by internal style sheets, so this text doesn't change size when I change the browser settings. How can I similarly control the text that is output by my date script, and other scripts?

Thanks.
 
Instead of using document.write, set the .innerText property
of a span that starts off empty - but with your chosen style applied.

eg: [tt]<span id="dateDisplay" class="smallFont"/>[/tt]

Then your script can be along the lines of:
Code:
function writeDate(strDateText){
 document.getElementById("dateDisplay").innerText = strDateText;
}

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
You can control the text by defining CSS classes in the elements that you are outputing in the document.write statement. In the class of the CSS specify the font-size.
When you actually specify the font-size the browser won't change the size of the font when changing the Text Size property in IE6.
Example:
Code:
document.write('<p class="paraClass">color1: ' + color + '</p>');
In your CSS in the head of your HTML you will have:
Code:
p.paraClass {
   font-size:12pt;
}
This is really more of an HTML/CSS forum question but oh well there's an answer for you.




<.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top