SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old October 9th, 2003, 08:19 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Trouble changing the text style of an element

Hello! I am attempting to write a script that will allow a user to change certain things about how a page is displayed. The PHP part has been completed, but I am having trouble with the JavaScript that does the changing. I have included it below:
Code:
<script language="JavaScript" type="text/javascript">
<!--
function changetext() {
/* preferably, I would like to apply this
to the whole document instead of just 
one part */
  var what = document.getElementByID("content");
  what.style.textSize = "4";
  what.style.color = "green";
  /* normally those values above would 
come from PHP variables */
}
document.onLoad = changetext;
//-->
</script>
<div id="content">Some text to style</div>


Can anyone see anything wrong with this code? Please be gentle and patient with me as I am no JS expert. In fact, I try to avoid it when possible.

Thank you very much for your help in advance!

Joe of Christ For Life
__________________
Check out 4Life today!

Last edited by Joe4JC : October 9th, 2003 at 08:30 PM.

Reply With Quote
  #2  
Old October 9th, 2003, 08:58 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Since JS is case sensitive, your calling of the getElementById will not work... simply change the last letter to lower-case, and you're rocking.

Also, I've not seen the "textSize" property before - try "fontSize" instead, and don't forget to specify your unit of measurement (px, pt, mm, etc)

Reply With Quote
  #3  
Old October 10th, 2003, 07:02 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Failing that, try creating classes with the different font sizes/colors and change the class instead of the style. I know I've made that work before. I can't help thinking that using what.style may not be cross-platform, but what.class seems to work across the board.

Reply With Quote
  #4  
Old October 10th, 2003, 08:26 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Yeah - you're on the right track dhouston - using classes in a seperate CSS file means that you can better seperate your presentation from your business logic (if you are a CSS purist...*coughFrankieShakescough* )

Bottom-line is, setting special case styles individually isn't usually a good idea as it makes updating a hassle.

Reply With Quote
  #5  
Old October 10th, 2003, 02:19 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thank you guys for your ideas; the suggestions stumpy first made are probably what I am looking for. Yes, I do use separate style sheets, but the reason I can not use classes for the text style is because the font size and colour values are coming from user input. I will let you guys know how well the changes work.

Joe

Reply With Quote
  #6  
Old October 14th, 2003, 09:37 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Allright guys, I made the changes and no dice. It took me several days to figure out that "document.onload" should have been "window.onload"! Oddly enough, I couldn't find any tutorials that mentioned that! Instead, I had to take it from another script.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Trouble changing the text style of an element


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway