473,396 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

dynamically changing background color HELP please

Hello,
I'm having a problem dynamically changing the color of a table background.

I'm not sure exactly how to word this, but I'll give an example.

I have a function called greentored(propname)

i want to be able to change the following to a different color:
document.all.propname.style.visibility

but substitute the propname with the variable that I'm sending over.

Here is what I had written before but it did not work, it should be easy to
understand what i'm trying to do:

function greentored(propname) {

changecolor = "document.all." + propname + ".style.background";

changecolor = "green";

}

I understand why this doesn't work because all i'm doing is reasigning
"changecolor" to equal green, rather then setting the property of the first
instance of "changecolor" to green. I hope I explained this well enough.

Thanks,

Billy
Jul 20 '05 #1
3 1955
In article <10*************@corp.supernews.com>, bi***@jimtown.org
enlightened us with...
Hello,
I'm having a problem dynamically changing the color of a table background.

And it only works in IE, too.
I'm not sure exactly how to word this, but I'll give an example.

I have a function called greentored(propname)

i want to be able to change the following to a different color:
document.all.propname.style.visibility


That is IE only syntax.
Not all of us use IE.

Visibility has no color. It is a property all by itself
(style.visibility). Most block elements have a style.backgroundColor
property. Some block elements, notably those with text like P and DIV,
have a style.color property.

I will assume that what you are sending is the name of an element.
For this to be cross-browser, what you need is an id.
I will show you a function that is for DOM browsers only (IE5+/NN6
+/Mozilla/Opera6+ etc). You're on your own for NN4 - I wiped my hands on
that one.

For this example, I have an element that has a background color
property.
<div id="myId">my div contents</div>
The function would then be called as
greenToRed("myId");

The function is defined in the head of the document as
(Watch for word-wrap)

function greenToRed(propname)
{
var changeColor="green";
if (document.getElementById(propname) && document.getElementById
(propname).style)
{
document.getElementById
(propname).style.backgroundColor=changeColor;
}
}

HTH

--
--
~kaeli~
Found God? If nobody claims Him in 30 days, He's yours to
keep.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
Thanks.... I've just started working on an addition to my website and you
reminded me i
need to test on Netscape as well as IE. yes, i did give my example wrong...
i
did mean "style.background" but your help was helpful none the less.
Thanks.

Billy

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message >
And it only works in IE, too.
I'm not sure exactly how to word this, but I'll give an example.

I have a function called greentored(propname)

i want to be able to change the following to a different color:
document.all.propname.style.visibility


That is IE only syntax.
Not all of us use IE.

Visibility has no color. It is a property all by itself
(style.visibility). Most block elements have a style.backgroundColor
property. Some block elements, notably those with text like P and DIV,
have a style.color property.

I will assume that what you are sending is the name of an element.
For this to be cross-browser, what you need is an id.
I will show you a function that is for DOM browsers only (IE5+/NN6
+/Mozilla/Opera6+ etc). You're on your own for NN4 - I wiped my hands on
that one.

For this example, I have an element that has a background color
property.
<div id="myId">my div contents</div>
The function would then be called as
greenToRed("myId");

The function is defined in the head of the document as
(Watch for word-wrap)

function greenToRed(propname)
{
var changeColor="green";
if (document.getElementById(propname) && document.getElementById
(propname).style)
{
document.getElementById
(propname).style.backgroundColor=changeColor;
}
}

HTH

--
--
~kaeli~
Found God? If nobody claims Him in 30 days, He's yours to
keep.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


Jul 20 '05 #3
In article <10*************@corp.supernews.com>, bi***@jimtown.org
enlightened us with...
Thanks.... I've just started working on an addition to my website and you
reminded me i
need to test on Netscape as well as IE.


Don't forget Opera. :)

And ask around for people to test with Safari and other browsers they
may have, especially IE for Mac.

--
--
~kaeli~
Never mess up an apology with an excuse.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: C A Upsdell | last post by:
I have a site where I am setting a style dynamically, using the JS statement: obj.style.backgroundImage = 'url(img/bak_page.jpg)'; where 'obj' is either document.getElementById(id), or...
4
by: Chris Mahoney | last post by:
Hi Currently I am setting the background image of my page by using the following code: <style type="text/css"> BODY { BACKGROUND-IMAGE: url(myimage.jpg) } </style> What I would like to do...
5
by: Jerry Camel | last post by:
I am interacting with an OCX on the client side. In the Onload event of the page, I am checking a property of the OCX: Is the port open or closed. If the port is open, I want a certain image to...
12
by: GaryDean | last post by:
In the original post I failed so indicate that I am using framework 1.1....... I need to be able to change the background color of a page from code. I found an answer to this question in...
5
by: GU | last post by:
Is it possible to use an simple cgi script to select one graphic dynamically and use this one as background image? if using <body background="/httpdocs/pics/test.jpg"> blah </body> i'll get...
2
by: Jason_SanDiego2006 | last post by:
Hello all, Hang with me, I'm a little new. I'm working on a web application in C# using ASP.NET 2.0 The goal of my application is to have pages whose styles can be dynamically changed based...
0
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
3
by: MLD | last post by:
PLEASE HELP! I would like to include a UL as a menu, styled by an included CSS Style Sheet. The problem I am having is how do I dynamically set the "active" page class using JavaScript to...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.