damselInDistress
asked on
Equivalent code for document.getElementById().className in Netscape?
I am trying to make this code work in Netscape, but I don't think Netscape supports .className to change the bgcolor of a cell. Please advise.
for(var x=1; x<=numTD; x++){
var selCell = cllPre+x;
//alert(selCell);
if(x == motionCount){
document.getElementById(cl lPre+x).cl assName = clsOne;
if((x-1) > 0){
document.getElementById(cl lPre+(x-1) ).classNam e = clsTwo;
}
}else{
document.getElementById(cl lPre+x).cl assName = clsNorm;
}
}
for(var x=1; x<=numTD; x++){
var selCell = cllPre+x;
//alert(selCell);
if(x == motionCount){
document.getElementById(cl
if((x-1) > 0){
document.getElementById(cl
}
}else{
document.getElementById(cl
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NS 6/7/Mozilla all definitely support the className property, I use it all the time in those browsers.
In fact, they support both
elementObject.className = "myClass";
and
elementObject.setAttribute ("calss", "myClass");
Let's have a link to your problem page or a complete code listing, please.
(And let's just forget about the NS4 crap -- goddess only knows I've tried!)
In fact, they support both
elementObject.className = "myClass";
and
elementObject.setAttribute
Let's have a link to your problem page or a complete code listing, please.
(And let's just forget about the NS4 crap -- goddess only knows I've tried!)
ASKER
<style>
TD.normal{
background-color: #000000;
}
TD.highlight{
background-color: blue;
}
TD.highlight2{
background-color: orange;
}
</style>
<script language="javascript">
function showStrobe(){
//alert("show the parking alert");
var parkingStrobe = new Strobe();
parkingStrobe.launch()
}
</script>
<%if showStrobe=1 then%>
<center>
<table Cellpadding="0" Cellspacing="2" width="770">
<tr name="trafficRow" id="trafficRow">
<td id="Cells1" width="39.5"></td>
<td id="Cells2" width="39.5"></td>
<td id="Cells3" width="39.5"></td>
<td id="Cells4" width="39.5"></td>
<td id="Cells5" width="39.5"></td>
<td bgcolor="black" width="375"><a href="#" target="_new"><img src="includes/homepage/Ale rt_graphic .jpg" border="0"></a></td>
<td id="Cells6" width="39.5"></td>
<td id="Cells7" width="39.5"></td>
<td id="Cells8" width="39.5"></td>
<td id="Cells9" width="39.5"></td>
<td id="Cells10" width="39.5"></td>
</tr>
</table>
</center>
<%end if%>
function Strobe(){
if(typeof(_Strobe_prototyp e_called) == 'undefined'){
_Strobe_prototype_called = true;
Strobe.prototype.changeBG = _changeBG;
Strobe.prototype.isEven = _isEven;
Strobe.prototype.launch = _launch;
Strobe.prototype.clear = _clear;
Strobe.prototype.wait = _wait;
Strobe.prototype.reset = _reset;
Strobe.prototype.counter = _counter;
Strobe.prototype.resetCell s = _resetCells;
}
this.speed = 50; //speed is in milliseconds
this.numCells = 10 //number of cells
this.cellPrefix = "cells" //prefix of the cell ID
this.classNormal = "normal"
this.classSelOne = "highlight"
this.classSelTwo = "highlight2"
var speed = this.speed;
var numCells = this.numCells;
var cellPrefix = this.cellPrefix;
var classNormal = this.classNormal;
var classSelOne = this.classSelOne;
var classSelTwo = this.classSelTwo;
var motionCount = 0;
var runThroughCount = 2;
var counter = 0;
var callCount = 0;
var timerCount = 0;
var globalStrobeInterval = 0;
function _resetCells(numTD, cllPre, clsNorm){
var motionCount = 0;
var runThroughCount = 2;
var counter = 0;
var callCount = 0;
for(var x=1; x<=numTD; x++){
var selCell = cllPre+x;
document.getElementById(cl lPre+x).cl assName = clsNorm;
}
}
function _changeBG(numTD, cllPre, clsNorm, clsOne, clsTwo){
//if it is even go up the winner
//if it is odd go down the river
if(Strobe.prototype.isEven (runThroug hCount)){
motionCount = motionCount + 1;
}else{
motionCount = motionCount - 1;
}
//if the motion count leaves the bounds it
//must be reset depending on which direction the
//river is flowing
if((motionCount > numTD) || (motionCount <= 0)){
runThroughCount = runThroughCount + 1;
if(Strobe.prototype.isEven (runThroug hCount)){
motionCount = 2;
}else{
motionCount = numTD-1;
}
}
//if runThroughCount is even we are going up the
//river, so increment the cells
//if not we are going down the river and
//decrement the cells
if(Strobe.prototype.isEven (runThroug hCount)){
for(var x=1; x<=numTD; x++){
var selCell = cllPre+x;
//alert(selCell);
if(x == motionCount){
document.getElementById(cl lPre+x).cl assName = clsOne;
if((x-1) > 0){
document.getElementById(cl lPre+(x-1) ).classNam e = clsTwo;
}
}else{
document.getElementById(cl lPre+x).cl assName = clsNorm;
}
}
}else{
for(var x=numTD; x>=1; x--){
if(x == motionCount){
document.getElementById(cl lPre+x).cl assName = clsOne;
if((x+1) <= numTD){
document.getElementById(cl lPre+(x+1) ).classNam e = clsTwo;
}
}else{
document.getElementById(cl lPre+x).cl assName = clsNorm;
}
}
}
callCount = callCount + 1
//alert(callCount);
if(callCount == 55){
callCount = 0;
Strobe.prototype.resetCell s(numTD, cllPre, clsNorm);
//alert("Interval="+global StrobeInte rval);
Strobe.prototype.clear(glo balStrobeI nterval);
Strobe.prototype.wait('Str obe.protot ype.launch ()', 5);
}
}
function _launch(){
//alert('launching');
globalStrobeInterval = setInterval('Strobe.protot ype.change BG('+numCe lls+',"'+c ellPrefix+ '","'+clas sNormal+'" , "'+classSelOne+'", "'+classSelTwo+'")', speed);
}
function _clear(interval1){
//clear the interval
//alert('Clearing Interval ' + interval1);
clearInterval(interval1);
}
function _reset(strobeInterval, numSecs){
var strobeReset = setInterval('Strobe.protot ype.launch ();Strobe. prototype. clear('+st robeInterv al+'); Strobe.prototype.clear('+s trobeReset +')', numSecs)
}
function _wait(func, secs){
globalStrobeInterval = setInterval('Strobe.protot ype.counte r('+ secs +')', 1000);
}
function _counter(secs){
timerCount = timerCount + 1
if(timerCount == secs){
timerCount = 0;
clearInterval(globalStrobe Interval)
Strobe.prototype.launch();
}
}
//end strobe class
}
function _isEven(num){
return (num%2) ? false:true;
}
TD.normal{
background-color: #000000;
}
TD.highlight{
background-color: blue;
}
TD.highlight2{
background-color: orange;
}
</style>
<script language="javascript">
function showStrobe(){
//alert("show the parking alert");
var parkingStrobe = new Strobe();
parkingStrobe.launch()
}
</script>
<%if showStrobe=1 then%>
<center>
<table Cellpadding="0" Cellspacing="2" width="770">
<tr name="trafficRow" id="trafficRow">
<td id="Cells1" width="39.5"></td>
<td id="Cells2" width="39.5"></td>
<td id="Cells3" width="39.5"></td>
<td id="Cells4" width="39.5"></td>
<td id="Cells5" width="39.5"></td>
<td bgcolor="black" width="375"><a href="#" target="_new"><img src="includes/homepage/Ale
<td id="Cells6" width="39.5"></td>
<td id="Cells7" width="39.5"></td>
<td id="Cells8" width="39.5"></td>
<td id="Cells9" width="39.5"></td>
<td id="Cells10" width="39.5"></td>
</tr>
</table>
</center>
<%end if%>
function Strobe(){
if(typeof(_Strobe_prototyp
_Strobe_prototype_called = true;
Strobe.prototype.changeBG = _changeBG;
Strobe.prototype.isEven = _isEven;
Strobe.prototype.launch = _launch;
Strobe.prototype.clear = _clear;
Strobe.prototype.wait = _wait;
Strobe.prototype.reset = _reset;
Strobe.prototype.counter = _counter;
Strobe.prototype.resetCell
}
this.speed = 50; //speed is in milliseconds
this.numCells = 10 //number of cells
this.cellPrefix = "cells" //prefix of the cell ID
this.classNormal = "normal"
this.classSelOne = "highlight"
this.classSelTwo = "highlight2"
var speed = this.speed;
var numCells = this.numCells;
var cellPrefix = this.cellPrefix;
var classNormal = this.classNormal;
var classSelOne = this.classSelOne;
var classSelTwo = this.classSelTwo;
var motionCount = 0;
var runThroughCount = 2;
var counter = 0;
var callCount = 0;
var timerCount = 0;
var globalStrobeInterval = 0;
function _resetCells(numTD, cllPre, clsNorm){
var motionCount = 0;
var runThroughCount = 2;
var counter = 0;
var callCount = 0;
for(var x=1; x<=numTD; x++){
var selCell = cllPre+x;
document.getElementById(cl
}
}
function _changeBG(numTD, cllPre, clsNorm, clsOne, clsTwo){
//if it is even go up the winner
//if it is odd go down the river
if(Strobe.prototype.isEven
motionCount = motionCount + 1;
}else{
motionCount = motionCount - 1;
}
//if the motion count leaves the bounds it
//must be reset depending on which direction the
//river is flowing
if((motionCount > numTD) || (motionCount <= 0)){
runThroughCount = runThroughCount + 1;
if(Strobe.prototype.isEven
motionCount = 2;
}else{
motionCount = numTD-1;
}
}
//if runThroughCount is even we are going up the
//river, so increment the cells
//if not we are going down the river and
//decrement the cells
if(Strobe.prototype.isEven
for(var x=1; x<=numTD; x++){
var selCell = cllPre+x;
//alert(selCell);
if(x == motionCount){
document.getElementById(cl
if((x-1) > 0){
document.getElementById(cl
}
}else{
document.getElementById(cl
}
}
}else{
for(var x=numTD; x>=1; x--){
if(x == motionCount){
document.getElementById(cl
if((x+1) <= numTD){
document.getElementById(cl
}
}else{
document.getElementById(cl
}
}
}
callCount = callCount + 1
//alert(callCount);
if(callCount == 55){
callCount = 0;
Strobe.prototype.resetCell
//alert("Interval="+global
Strobe.prototype.clear(glo
Strobe.prototype.wait('Str
}
}
function _launch(){
//alert('launching');
globalStrobeInterval = setInterval('Strobe.protot
}
function _clear(interval1){
//clear the interval
//alert('Clearing Interval ' + interval1);
clearInterval(interval1);
}
function _reset(strobeInterval, numSecs){
var strobeReset = setInterval('Strobe.protot
}
function _wait(func, secs){
globalStrobeInterval = setInterval('Strobe.protot
}
function _counter(secs){
timerCount = timerCount + 1
if(timerCount == secs){
timerCount = 0;
clearInterval(globalStrobe
Strobe.prototype.launch();
}
}
//end strobe class
}
function _isEven(num){
return (num%2) ? false:true;
}
Just thought of something -- are clsOne, ClsTwo, etc. the actual names of the classes? Then you need to be using
document.getElementById(cl lPre+x).cl assName = "clsOne";
etc.
document.getElementById(cl
etc.
Guess not.
I've never seen so many references to a function prototype in a single piece of code before -- you a Java programmer by any chance? I've been writing too much VBScript lately, I'm starting to forget how to read code like this. ;-)
Might be time to stick in some alerts and see what's getting passed for the id and classname values at that point.
Are you seeing any errors in the JS console? Also, have you tried Venkman out on this thing?
I've never seen so many references to a function prototype in a single piece of code before -- you a Java programmer by any chance? I've been writing too much VBScript lately, I'm starting to forget how to read code like this. ;-)
Might be time to stick in some alerts and see what's getting passed for the id and classname values at that point.
Are you seeing any errors in the JS console? Also, have you tried Venkman out on this thing?
ASKER
truthfully, I did not write this, am just stuck trying to make it work in Netscape 6/7. I am not getting any errors, it just doesn't work. When I do an alert
//alert(selCell);
in IE, I can see that it is incrementing. In Netscape, it is not.
I have been told that if I can't get this working in Netscape, no big deal, but I would like to anyway. Unfortunately, I am in over my head on this one :)
//alert(selCell);
in IE, I can see that it is incrementing. In Netscape, it is not.
I have been told that if I can't get this working in Netscape, no big deal, but I would like to anyway. Unfortunately, I am in over my head on this one :)
Might be a good time to get acquainted with Venkman, then.
http://www.svendtofte.com/code/learning_venkman/
The only way you'll ever be able to figure out what's not happening is to step through it with a debugger, now's as good a time as any to get acquainted.
http://www.svendtofte.com/code/learning_venkman/
The only way you'll ever be able to figure out what's not happening is to step through it with a debugger, now's as good a time as any to get acquainted.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: Zontar {http:#9667576}
Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: Zontar {http:#9667576}
Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
ASKER