PDA

View Full Version : Undefined Error


Jt107
11-21-2002, 05:04 PM
I am not very good on javascript, but I have deal with an error on a javascript menu. When the menu item has two or more levels, it works fine, but when it is single level, it give me a debugging error which I don't know how to tacle with Javascripts:
here is part of the code:
...
function MoveMenuButtons(menu,submenu,pixels) // move menu image buttons to accomodate expanded links
{
for (i=1; i < MenuNames.length; i++)
{
if (MenuNames[i] == menu)
{
var menuLoc = i + 1; // determine which menu is being accessed
}
}
if (submenu != '' && pixels != '')
{
extraHeight = pixels;
}
else
{
extraHeight = 0;
//return false;
}

baseHeight = MenuLevelHeight[0];
eachHeight = MenuLevelHeight[1];
arrayName = menu.toLowerCase();
sizeOfArray = eval(arrayName + '[0]');
alert("sizeOfArray = " +sizeOfArray);
expandedSize = extraHeight + baseHeight + (eachHeight * sizeOfArray); // determine total amount of pixel displacement
for (j = (MenuNames.length - 1); j >= menuLoc; j--)
{ alert("extraHeight = " + extraHeight+"baseHeight = "+baseHeight+ "eachHeight = "+eachHeight +"sizeOfArray = "+sizeOfArray+" expandedSize = "+expandedSize);
finalSize = expandedSize + MenuButtonTop[j];
totExpSize = finalSize + "px";
menuNameStr = MenuNames[j];
ThisMenuStr = eval(menuNameStr + 'Button.style');
ThisMenuStr.top = totExpSize; // move each button by displaced amount of pixels
}
return true;
}

.....

sizeOfArray is undefined on single level. Please help,

Thanks

glenngv
11-22-2002, 02:31 AM
when it is a single level, the menu item has single level thus, it is not an array

arrayName = menu.toLowerCase();
sizeOfArray = eval(arrayName + '[0]');
alert("sizeOfArray = " +sizeOfArray);

so you append [0] when it has 2 levels only.

Jt107
11-22-2002, 02:45 PM
Thanks, or I need to limit the script to execute only it has two levels.