Link to home
Start Free TrialLog in
Avatar of damselInDistress
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(cllPre+x).className = clsOne;
                                                
      if((x-1) > 0){
        document.getElementById(cllPre+(x-1)).className = clsTwo;
      }

  }else{
    document.getElementById(cllPre+x).className = clsNorm;

  }

}
ASKER CERTIFIED SOLUTION
Avatar of Zontar
Zontar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of damselInDistress
damselInDistress

ASKER

Actually, it doesn't seem to work in Netscape 6 or 7.  I don't care about 4.
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!)
     <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/Alert_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_prototype_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.resetCells = _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(cllPre+x).className = 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(runThroughCount)){
                                          
                                          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(runThroughCount)){
                                          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(runThroughCount)){
                                    
                                    for(var x=1; x<=numTD; x++){
                                          var selCell = cllPre+x;
                                          //alert(selCell);
                                          if(x == motionCount){
                                                document.getElementById(cllPre+x).className = clsOne;
                                                
                                                if((x-1) > 0){
                                                document.getElementById(cllPre+(x-1)).className = clsTwo;
                                                }
                                                      
                                          }else{
                                                document.getElementById(cllPre+x).className = clsNorm;
                                                
                                          }
                                                
                                    }
                              }else{
                                    for(var x=numTD; x>=1; x--){
                                          
                                          if(x == motionCount){
                                                document.getElementById(cllPre+x).className = clsOne;
                                                
                                                
                                                if((x+1) <= numTD){
                                                document.getElementById(cllPre+(x+1)).className = clsTwo;
                                                }
                                          }else{
                                                document.getElementById(cllPre+x).className = clsNorm;
                                                
                                          }
                                    }
                              }
                              
                              callCount = callCount + 1
                              //alert(callCount);
                              if(callCount == 55){
                                    callCount = 0;
                                    Strobe.prototype.resetCells(numTD, cllPre, clsNorm);
                                    //alert("Interval="+globalStrobeInterval);
                                    Strobe.prototype.clear(globalStrobeInterval);
                                    Strobe.prototype.wait('Strobe.prototype.launch()', 5);
                              }

                  }
            
                  
                  function _launch(){
                        //alert('launching');
                        globalStrobeInterval = setInterval('Strobe.prototype.changeBG('+numCells+',"'+cellPrefix+'","'+classNormal+'", "'+classSelOne+'", "'+classSelTwo+'")', speed);
                        
                  }
                  
                  
                  function _clear(interval1){
                        //clear the interval
                        //alert('Clearing Interval ' + interval1);
                        clearInterval(interval1);
                  }
                  
                  
                  function _reset(strobeInterval, numSecs){
                        var strobeReset = setInterval('Strobe.prototype.launch();Strobe.prototype.clear('+strobeInterval+');  Strobe.prototype.clear('+strobeReset+')', numSecs)
                        
                  }
                  
                  function _wait(func, secs){
                        globalStrobeInterval = setInterval('Strobe.prototype.counter('+ secs +')', 1000);
                  }
                  
                  function _counter(secs){
                        timerCount = timerCount + 1
                        
                        if(timerCount == secs){
                              timerCount = 0;
                              clearInterval(globalStrobeInterval)
                              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(cllPre+x).className = "clsOne";

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?
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 :)
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.
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