Javascript: document.all null or not an object

L

Leila

Folks

I have an html file which looks like this:

..
..
..
<body onLoad="WindowOnLoad();">
..
..
..
<div id="strategy_asp" style="visibility:hidden;">HTML CODE HERE</div>
<div id="organisation_asp" style="visibility:hidden;">HTML CODE
HERE</div>
<div id ="people.asp" style="visibility:hidden;">HTML CODE HERE</div>
..
..
..

I also have a javascript function which retrieves the URL of the page
you're on and should then display the appropriate content for that
page:

function WindowOnLoad() {

// this function will detect what page I am on using the javascript
href function
// and then depending on the outcome, it will switch the <div> tag for
that particular page
// on or off

var src = self.location.href;
src = (src.substring(src.lastIndexOf("/") + 1,
src.length).toLowerCase());

// replace "." in URL with "_"
src = src.replace('.', '_')

if (document.layers) {
eval("document.layers['" + src + "'].style.visibility = 'show';");
} else if(document.all) {
eval("document.all." + src + ".style.visibility = 'visible'");
} else if(document.getElementById) {
eval("document.getElementById('" + src + "').style.style.visibility =
'visible';");
}
}

However, I keep getting this error when I click on strategy.asp, for
example:
document.all.strategy_asp.style is null or not an object
This is infuriating. What am I doing wrong???
 
R

Randy Webb

Leila said:
Folks

I have an html file which looks like this:

if (document.layers) {
eval("document.layers['" + src + "'].style.visibility = 'show';");

eval not needed at all.
} else if(document.all) {
eval("document.all." + src + ".style.visibility = 'visible'");

document.all[src].style.visibility
again, no eval needed.
} else if(document.getElementById) {
eval("document.getElementById('" + src + "').style.style.visibility =
'visible';");

document.getElementById(src).style.visibility

un-needed eval and an extra .style in it
}
}

However, I keep getting this error when I click on strategy.asp, for
example:
document.all.strategy_asp.style is null or not an object
This is infuriating. What am I doing wrong???

1) You are using an eval that is not needed.
2) You probably dont have a div named strategy_asp
3) You are taking the document.all branch early, take the getElementById
branch first.
 

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,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top