tags:

views:

47

answers:

1

I asked this yesterday but could not reply as i was not registered , I tried out the suggestions that HoLyVieR,Ryan Kinal and Vagabond said, but non of them seem to work.

I have taken out the array as that seem to be the suggested problem and solution but now the code does not work at all but shows no error's.

The original question is here http://stackoverflow.com/questions/3512817/object-expected-error-in-internet-explorer

<script language="JavaScript">
function toggleLayer( whichLayer )
{
  var elem, vis,eelem, vvis;

  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;


for (i=0;i<25;i++)
{
    eelem = document.getElementById( 'sub'+i );
    vvis = eelem.style;
    if(eelem==elem){
        vvis.display = "block";
    } else {
        vvis.display = "none";
    }
}

  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
</script>
A: 

You'll get this error if anything from sub0, sub1, ... sub24 doesn't exist. Are your elements perhaps named sub1 - sub25, so that document.getelementById('sub0'); doesn't find anything?

Your first section of code checks if document.getElementById exist, and if not, it falls back on document.all or document.layers. In the block of code immediately after that, you assume that document.getElementById exists. You should be consistent in your assumptions, whichever way you decide to go.

David Hedlund