Dynamic table data background color in NN

M

Michael McClune

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.className = "white_bg";
// -or- member.bgcolor = "white"
}
}
// end javascript -->
</script>

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

Thanks

Mike
 
R

Randy Webb

Michael said:
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.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.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
 
M

Michael McClune

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 said:
Michael said:
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.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.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
 
K

kaeli

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");
}



--
 
M

Michael McClune

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?
 
K

kaeli

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").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.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
 
M

Michael McClune

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 said:
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").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.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
 
K

kaeli

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. ;)


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top