Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript: document.all null or not an object

Reply
Thread Tools

Javascript: document.all null or not an object

 
 
Leila
Guest
Posts: n/a
 
      07-29-2004
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???
 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      07-29-2004
Leila wrote:
> Folks
>
> I have an html file which looks like this:
>


<--snip-->

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASPX page jscript rt error: null is null or not an object Cirene ASP .Net 1 06-09-2008 07:59 PM
XMLHTTP - null is null or not an object Tim Platt Javascript 0 06-04-2007 08:42 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
difference between null object and null string gokul.b@gmail.com Java 16 10-12-2005 06:43 PM
IE SP2 solution for "null is null or not an object" and "broken" insertCell/insertRow putty Javascript 1 04-05-2005 07:11 PM



Advertisments