473,756 Members | 7,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(prop name)

i want to be able to change the following to a different color:
document.all.pr opname.style.vi sibility

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(prop name) {

changecolor = "document.a ll." + propname + ".style.backgro und";

changecolor = "green";

}

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

Thanks,

Billy
Jul 20 '05 #1
3 2014
In article <10************ *@corp.supernew s.com>, bi***@jimtown.o rg
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(prop name)

i want to be able to change the following to a different color:
document.all.pr opname.style.vi sibility


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

Visibility has no color. It is a property all by itself
(style.visibili ty). Most block elements have a style.backgroun dColor
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("myI d");

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

function greenToRed(prop name)
{
var changeColor="gr een";
if (document.getEl ementById(propn ame) && document.getEle mentById
(propname).styl e)
{
document.getEle mentById
(propname).styl e.backgroundCol or=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.backgrou nd" but your help was helpful none the less.
Thanks.

Billy

"kaeli" <ti******@NOSPA M.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(prop name)

i want to be able to change the following to a different color:
document.all.pr opname.style.vi sibility


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

Visibility has no color. It is a property all by itself
(style.visibili ty). Most block elements have a style.backgroun dColor
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("myI d");

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

function greenToRed(prop name)
{
var changeColor="gr een";
if (document.getEl ementById(propn ame) && document.getEle mentById
(propname).styl e)
{
document.getEle mentById
(propname).styl e.backgroundCol or=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.supernew s.com>, bi***@jimtown.o rg
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
2889
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 document.all, depending on browser support. This works just fine, with just one small problem: I want to set the style ONLY for screen media, not for printer media; the above statement appears to
4
3782
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 is change the background image dynamically. My guess
5
1910
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 appear. If the port is closed, a different image. Sounds pretty straight forward. Since this is dependent upon a property of a client side component, I can't do this with VB .net on the server, right? So I was trying to use vbscript on the...
12
4552
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 another forum from Peter Huang that said that an id="bg" as follows... <body MS_POSITIONING="GridLayout" runat="server" id="bg"> then we could do the following in our codebehind file....
5
2128
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 this backgroung picture. but i want to get the backgroungimage dynamically. so i'd like to use an simple cgi script <body background="/cgi-bin/test.pl"> blah </body>
2
2167
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 on the logged-in user's saved preferences. The user can define their own styles (font-size, font-family, color, etc.)
0
1374
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 tabpanels such as:Catalog,Terms,SiteMap.ViewCart ,etc. All the jewellery Intro is in the Catalog panel. when I first click the Catalog panel it Introduces me all the main types of the jewellery(It's all done dynamically from the cs file).The...
3
4567
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 change each time I click on a new list item? I have found a bunch of examples but none that really accomplish what I need.
6
2559
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
0
9117
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9679
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8542
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4955
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3651
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.