473,396 Members | 1,872 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.

Dynamic table data background color in NN

Is it possible to change a <TD> background color on the fly with NN? There
are a long list of members info that I want to alternate the background
color of.
I have tried calling variation of the shown function "somefunction(this)"
from within each <TD> and accessing the <TD> style to no avail.
This works in IE:

<script type="text/JavaScript" language="JavaScript" >
<!--
function colortable(){
for (var i=0; i < pmdtable.rows.length; i += 2){
member[i].className = "white_bg";
// -or- member[i].bgcolor = "white"
}
}
// end javascript -->
</script>

<body onload = "colortable()">
<table id="pmdtable">
<tr>
<td id="member">
name
whatever
</td>
...
...
</tr>
</table>

Thanks

Mike
Jul 20 '05 #1
7 1721
Michael McClune wrote:
Is it possible to change a <TD> background color on the fly with NN? There
are a long list of members info that I want to alternate the background
color of.
I have tried calling variation of the shown function "somefunction(this)"
from within each <TD> and accessing the <TD> style to no avail.
This works in IE:

<script type="text/JavaScript" language="JavaScript" >
<!--
function colortable(){
for (var i=0; i < pmdtable.rows.length; i += 2){
member[i].className = "white_bg";
In both of the above lines, you are relying on the IE shortcut method of
obtaining a reference to an object.
// -or- member[i].bgcolor = "white"
}
}
// end javascript -->
</script>

<body onload = "colortable()">
<table id="pmdtable">
<tr>
<td id="member">
name
whatever
</td>
...
...
</tr>
</table>


Which version of Netscape? How you do it in Netscape 6/7 is totally
different than how you would do it in Netscape 4.xx

--
Randy

Jul 20 '05 #2
I have Netscape 7.1 and I need this to work with as broad a range of
browsers as possible. Interestingly enough I tested for each of
document.getElementById, document.all and document.layers with simple if
/else if... and alert() if OK script. IE supported document.all, NN didn't
seem to support to any of these.

Regards

"Randy Webb" <hi************@aol.com> wrote in message
news:Da********************@comcast.com...
Michael McClune wrote:
Is it possible to change a <TD> background color on the fly with NN? There are a long list of members info that I want to alternate the background
color of.
I have tried calling variation of the shown function "somefunction(this)" from within each <TD> and accessing the <TD> style to no avail.
This works in IE:

<script type="text/JavaScript" language="JavaScript" >
<!--
function colortable(){
for (var i=0; i < pmdtable.rows.length; i += 2){
member[i].className = "white_bg";


In both of the above lines, you are relying on the IE shortcut method of
obtaining a reference to an object.
// -or- member[i].bgcolor = "white"
}
}
// end javascript -->
</script>

<body onload = "colortable()">
<table id="pmdtable">
<tr>
<td id="member">
name
whatever
</td>
...
...
</tr>
</table>


Which version of Netscape? How you do it in Netscape 6/7 is totally
different than how you would do it in Netscape 4.xx

--
Randy

Jul 20 '05 #3
In article <7n********************@twister.tampabay.rr.com> ,
mm******@cfl.rr.com enlightened us with...
I have Netscape 7.1 and I need this to work with as broad a range of
browsers as possible.
It is VERY hard to get dynamic page elements in old browsers, like NN4x.
It is impossible in some.
Interestingly enough I tested for each of
document.getElementById, document.all and document.layers with simple if
/else if... and alert() if OK script. IE supported document.all, NN didn't
seem to support to any of these.


Sure it deos. I do it all the time.
if (document.getElementById && !document.all)
{
// netscape 6,7,Mozilla, etc
alert("NN 7");
}
else if (document.all && document.getElementById)
{
// new IE, opera, etc
alert("IE 6");
}
else if (document.all && !document.getElementById)
{
// old IE
alert("IE 4");
}
else if (document.layers)
{
// old NN
alert("NN 4");
}

--
--
~kaeli~
No one is listening until you make a mistake.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4
For NN is there an array of, in this case, "members" I can iterate over as I
did with the IE script e.g. member[#].className?

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <7n********************@twister.tampabay.rr.com> ,
mm******@cfl.rr.com enlightened us with...
I have Netscape 7.1 and I need this to work with as broad a range of
browsers as possible.


It is VERY hard to get dynamic page elements in old browsers, like NN4x.
It is impossible in some.
Interestingly enough I tested for each of
document.getElementById, document.all and document.layers with simple if
/else if... and alert() if OK script. IE supported document.all, NN didn't seem to support to any of these.


Sure it deos. I do it all the time.
if (document.getElementById && !document.all)
{
// netscape 6,7,Mozilla, etc
alert("NN 7");
}
else if (document.all && document.getElementById)
{
// new IE, opera, etc
alert("IE 6");
}
else if (document.all && !document.getElementById)
{
// old IE
alert("IE 4");
}
else if (document.layers)
{
// old NN
alert("NN 4");
}

--
--
~kaeli~
No one is listening until you make a mistake.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #5
In article <LV********************@twister.tampabay.rr.com> ,
mm******@cfl.rr.com enlightened us with...
For NN is there an array of, in this case, "members" I can iterate over as I
did with the IE script e.g. member[#].className?


For NN4?
I don't think so. NN4 only did layers, and that was a huge pain. Most of
us have just stopped programming for it and let our scripts degrade so
that the stuff doesn't crash old browsers.
I don't do commercial sites, so I have a caveat that my users must use
NN6+ if I have need of DHTML. My internet sites don't do anything fancy
that won't work in all browsers (as a requirement for function; they may
look prettier).

NN6+ can do the same DOM things as IE, for the most part, but your
script used IE only shortcuts, not DOM methods.

The standard is that all ids on a page should be unique.
NAME your cells the same name, then use getElementsByName to get all the
tags and style as appropriate. Note that getElementsByName is DOM only
and will not work in old browsers, so the check
if (document.getElementsByName)
should be used to avoid crashes.

I think you can say
document.getElementsByName("method")[i].className=class
but have not tried it. If that works, you can just use a loop to change
the class for all elements with that name.

So...not sure, but try this. (IE5+/NN6+/compatible)
<script type="text/javascript" language="javascript" >
function colortable(){
var members = document.getElementsByName("member")
for (var i=0; i < members.length; i += 2){
members[i].className = "white_bg";
}
}
</script>

<body onload = "colortable()">
<table id="pmdtable">
<tr>
<td name="member">
name
whatever
</td>
...
...
</tr>
</table>

--
--
~kaeli~
Murphy's Law #2030: If at first you don't succeed, destroy
all evidence that you tried.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #6
Thank you kaeli. It should be noted that the script does not have to use IE
shortcuts but I'm getting older and lazier, and I use IE for which the
script worked... until I fetched Netscape. I suppose those folks with NN may
just have to look at plain blue rows. I will give your ideas a try.

It is unfortunate that 57% of those visiting the site use NN 4 (grin)

Old minds are like old horses; you must exercise them if you wish to keep
them in working order.

- John Quincy Adams

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <LV********************@twister.tampabay.rr.com> ,
mm******@cfl.rr.com enlightened us with...
For NN is there an array of, in this case, "members" I can iterate over as I did with the IE script e.g. member[#].className?


For NN4?
I don't think so. NN4 only did layers, and that was a huge pain. Most of
us have just stopped programming for it and let our scripts degrade so
that the stuff doesn't crash old browsers.
I don't do commercial sites, so I have a caveat that my users must use
NN6+ if I have need of DHTML. My internet sites don't do anything fancy
that won't work in all browsers (as a requirement for function; they may
look prettier).

NN6+ can do the same DOM things as IE, for the most part, but your
script used IE only shortcuts, not DOM methods.

The standard is that all ids on a page should be unique.
NAME your cells the same name, then use getElementsByName to get all the
tags and style as appropriate. Note that getElementsByName is DOM only
and will not work in old browsers, so the check
if (document.getElementsByName)
should be used to avoid crashes.

I think you can say
document.getElementsByName("method")[i].className=class
but have not tried it. If that works, you can just use a loop to change
the class for all elements with that name.

So...not sure, but try this. (IE5+/NN6+/compatible)
<script type="text/javascript" language="javascript" >
function colortable(){
var members = document.getElementsByName("member")
for (var i=0; i < members.length; i += 2){
members[i].className = "white_bg";
}
}
</script>

<body onload = "colortable()">
<table id="pmdtable">
<tr>
<td name="member">
name
whatever
</td>
...
...
</tr>
</table>

--
--
~kaeli~
Murphy's Law #2030: If at first you don't succeed, destroy
all evidence that you tried.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #7
In article <zw*******************@twister.tampabay.rr.com>,
mm******@cfl.rr.com enlightened us with...
Thank you kaeli. It should be noted that the script does not have to use IE
shortcuts but I'm getting older and lazier, and I use IE for which the
script worked... until I fetched Netscape. I suppose those folks with NN may
just have to look at plain blue rows.
Yes, for NN4.
Don't worry, they're used to it. *smirk*

Old minds are like old horses; you must exercise them if you wish to keep
them in working order.


How true!
hehe
If you really want to cater to the NN4 folks, what you'd have to do is
dynamically write the table to a layer with document.write statements.
However, the less people cater to them, the more they'll upgrade,
assuming they have the option. ;)
--
--
~kaeli~
Why do people who know the least know it the loudest?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #8

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

Similar topics

1
by: Michael | last post by:
How can I use onclick to change a table cell background color. I know I can use this.className=? to change the classname. But then I would have to put the code into every single table cell. I...
5
by: Jason Chan | last post by:
I have a cell in table with background color set to red, for example <table> <tr><td bgcolor="red">ABC</td></tr> </table> I print this page to a color printer, however, no background color is...
13
by: Gary | last post by:
I have a table with a form consisting of several checkboxes and I'm wondering if its possible to change the table row background color on mouseover or hover and make it stay that color when the...
2
by: ssb | last post by:
Hello, Am interested in knowing, how MS-access stores data internally... When I create a table and load records into it, I dont find any "data file" being created that possibles stores my...
0
by: Bruce W.1 | last post by:
I'm trying to put together a horizontal tab nav in a User Control, and I want to have some mouseOver behavior. This could easily be done with just CSS, however hyperlinking this way (client-side)...
10
by: Karl-Inge Reknes | last post by:
Hi, Can anyone tell me how to change a table cells background color or background image in runtime with C#. Karl-Inge
1
by: iceburn17 | last post by:
Hi, Can anyone can tell me how to change a table row background color when I click a button? most of the tutorial I found add the event on the TR onclick event, but that not I want. It is...
1
by: dowlingpc | last post by:
Has anyone discovered a way to control the background color of individual "cells" based on the cells content? When the cell has a negative value or is without content I'd like to change its...
2
by: mdejac | last post by:
I was wondering why the background color is not showing up in Mozilla. When I view the page there is a light blue background, when it should be black. Thank you for any help. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.