Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2004, 10:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default document null or not an object

Hi there

I'm trying to compile a sliding menu but am running into problems on these lines:

else {
menuObj.top = nextPos
}

The error message reads: Error: menuObj is null or not an object

Here's my code for the menu:

<script type="text/javascript" language="javascript">

<!--Hide from older browsers

if (document.getElementByID) {
stdBrowser = true
}
else {
stdBrowser = false
}

function toggleMenu(currElem,nextPos) {
if (stdBrowser) {
menuObj = document.getElementById(currElem).style
}
else {
menuObj = eval("document." + currElem)
}
if (toggleMenu.arguments.length == 1) {
if (parseInt(menuObj.top) == -5) {
nextPos = -90
}
else {
nextPos = -5
}
}
if (stdBrowser) {
menuObj.top = nextPos + "px"
}
else {
menuObj.top = nextPos
}
}
//end hiding-->
</script>

Any help would be greatly appreciated.

thanks

Adam
 
Old February 18th, 2004, 11:47 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Hard to tell in isolation but you have
Code:
function toggleMenu(currElem,nextPos) {
if (stdBrowser) {
menuObj = document.getElementById(currElem).style
}
else {
menuObj = eval("document." + currElem)
}
These two do not equate. I would change it to this (you do not need eval for this, in fact I've never seen a case for eval):
Code:
function toggleMenu(currElem,nextPos) {
if (stdBrowser) {
menuObj = document.getElementById(currElem)
}
else {
menuObj = document.all[currElem];
}
//rest of stuff
If you actually do want the style object instead of the object have:
Code:
function toggleMenu(currElem,nextPos) {
if (stdBrowser) {
menuObj = document.getElementById(currElem).style
}
else {
menuObj = document.all[currElem].style;
}
//rest of stuff


--

Joe
 
Old February 18th, 2004, 01:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

thanks Joe, will give it a bash.





Similar Threads
Thread Thread Starter Forum Replies Last Post
null or not an object crmpicco Classic ASP Basics 0 July 4th, 2005 05:58 AM
null or not a object crmpicco Javascript How-To 5 March 22nd, 2005 10:48 AM
is null or not an object fosterjim Javascript How-To 1 January 24th, 2005 02:11 PM
document.lcoation.href is null or not an object IceXia Javascript How-To 2 November 24th, 2004 04:44 AM
document null or not an object Adam H-W Javascript 2 April 22nd, 2004 05:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.