Click to See Complete Forum and Search --> : JavaScript Menu (object required error)


lahmayes
04-04-2004, 12:55 PM
does anyone see anything wrong with this script? i got this script from dreamweaver (i know i know, lol please dont give me a hard time) but anyways it originally had 7 items and i changed it to 9, it didnt like it though.



<!--
var menuitem1 = new menu(9,1,"hidden");
var menuitem2 = new menu(9,2,"hidden");
var menuitem3 = new menu(9,3,"hidden");
var menuitem4 = new menu(9,4,"hidden");
var menuitem5 = new menu(9,5,"hidden");
var menuitem6 = new menu(9,6,"hidden");
var menuitem7 = new menu(9,7,"hidden");
var menuitem8 = new menu(9,8,"hidden");
var menuitem9 = new menu(9,9,"hidden");
var time = 0001;
var numofitems = 9;

//menu constructor
function menu(allitems,thisitem,startstate){
callname= "gl"+thisitem;
divname="subglobal"+thisitem;
this.numberofmenuitems = 9;
this.caller = document.getElementById(callname);
this.thediv = document.getElementById(divname);
this.thediv.style.visibility = startstate;
}

//menu methods
function ehandler(event,theobj){
for (var i=1; i<= theobj.numberofmenuitems; i++){
var shutdiv =eval( "menuitem"+i+".thediv");
shutdiv.style.visibility="hidden";
}
theobj.thediv.style.visibility="visible";
}

function closesubnav(event){
if ((event.clientY <48)||(event.clientY > 107)){
for (var i=1; i<= numofitems; i++){
var shutdiv =eval('menuitem'+i+'.thediv');
shutdiv.style.visibility='hidden';
}
}
}

// -->


this line "this.thediv.style.visibility = startstate;"flags an error on, it says object required, but i dont know enough js to know what it wants. thanks guys..
~Hal

Khalid Ali
04-04-2004, 01:00 PM
put an alert before this line
divname="subglobal"+thisitem;
and see if the thisitem does have a vlaue in it,if it passes then make sure that you put anohter check after this line
this.thediv = document.getElementById(divname);

and see if the reference to this item is being created.

lahmayes
04-04-2004, 01:14 PM
ok im not quite sure what i was supposed to put in the alerts but this is what i did, i put alert(divname) first, where you said to, that worked fine i got 9 alerts (subglobal1, subglobal2...) then i put alert(thediv) under the line you said (the one with getElementById) and i got a bunch of errors. i can give them to you if you want, it was a ton though.

lahmayes
04-04-2004, 01:20 PM
ok i split the var's "menuitem#" into a seperate js files (cause tahts how dreamweaver originally had them) and put them at the bottom of the page (thats where dw had them too). now i dont get object required i get menuitem1 is not defined, lol which one is worse?

EDIT: the menu seems to work fine, it just gets a debug error everytime the page loads.

lahmayes
04-04-2004, 10:02 PM
:-/ anyone?

lahmayes
04-05-2004, 10:18 AM
ok heres what i did so far, now instead of "menuitem1 is null or not an object" i get "style is null or not an object" you can see the page the script is on at www.alabu.com/hal/


var menuitem1 = 0;
var menuitem2 = 0;
var menuitem3 = 0;
var menuitem4 = 0;
var time = 3000;
var numofitems = 4;

//menu constructor
function menu(allitems,thisitem,startstate){
callname= "gl"+thisitem;
divname="subglobal"+thisitem;
this.numberofmenuitems = 4;
this.caller = document.getElementById(callname);
this.thediv = document.getElementById(divname);
this.thediv.style.visibility = startstate;
}

//menu methods
function ehandler(event,theobj){
for (var i=1; i<= theobj.numberofmenuitems; i++){
var shutdiv =eval( "menuitem"+i+".thediv");
shutdiv.style.visibility="hidden";
}
theobj.thediv.style.visibility="visible";
}

function closesubnav(event){
if ((event.clientY <48)||(event.clientY > 107)){
for (var i=1; i<= numofitems; i++){
var shutdiv =eval('menuitem'+i+'.thediv');
shutdiv.style.visibility='hidden';
}
}
}


and then at the bottom of the page


var menuitem1 = new menu(4,1,"hidden");
var menuitem2 = new menu(4,2,"hidden");
var menuitem3 = new menu(4,3,"hidden");
var menuitem4 = new menu(4,4,"hidden");


any ideas what to do?

lahmayes
04-06-2004, 07:58 AM
*cough* i feel like im being a pain replying to my own post 4 times in a row, can anyone help me out? this post just keeps getting pushed down.