473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Javascript: document.all null or not an object

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???
Jul 23 '05 #1
1 9514
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.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: nickolausp | last post by:
When embedding a JavaScript document.write within a JavaScript document.write in Netscape 4.x (example below), the text is written out of logical order. <script type="text/javascript"> <!--...
8
by: Robert | last post by:
Hello all, Why reference cannot be able to represent a NULL object? Best regards, Robert
4
by: dschruth | last post by:
Hello. Can anybody solve this problem? I am using a server-side language (PERL) to *try* to POST data to a HTTPS login script that doesn't have a standard "submit" button. The form appears...
1
by: bonnie.tangyn | last post by:
Hello all Would it be possible to store javascript document.forms.value to ASP session as global variable? If it is not possible, how can I pass the javascript document.forms.value to...
2
by: bonnie.tangyn | last post by:
Hello all Would it be possible to store javascript document.forms.value to ASP session as global variable? If it is not possible, how can I pass the javascript document.forms.value to...
3
by: sfeher | last post by:
Hi All, The following code returns a valid xmlDoc (since I can evaluate and selectNodes) but its value is "xmlDoc= null" ?! Or at least this is what the FireBug shows and (xmlDoc===null) is...
15
by: Tarun Mistry | last post by:
Hi guys, what is the best/correct way to check for a NULL object? I.e. myClass test; if(test == null) {}
3
by: toton | last post by:
Hi, In some cases when my function returns, I need to return a object of null state. This is when I return object by value. (Just like for by pointer, I can return a null pointer ). It has to be...
1
by: Zytan | last post by:
if (webBrowserControl.Document == null) is throwing an InvalidCastException. PLEASE NOTE: ***The function being called is being called from a thread OTHER THAN than the one that created the...
3
karthickkuchanur
by: karthickkuchanur | last post by:
Dear Experts, Please let me know what is the difference between difference between object !=null and null !=object,I already google it but i can't able to find the right answer
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.