gib65
03-14-2012, 02:42 PM
Hello,
I have a website that I need help with. You can visit it here: http://www.shahspace.com/bow/home.html. To see what I need help with, click on the services menu item and observe the alert message that comes up. It should say "point 1".
Here is the code that executes that:
function enableScrolling(menuName)
{
alert("point 1");
var menu = document.getElemenetById(menuName);
alert("point 2");
...
}
As you can see, there should be a second alert message that says "point 2", but there isn't. The script is crash when I try to assign to menu the object returned by document.getElementById(menuName). I have verified that menuName is correct. So why would this be crashing?
To get a fuller understanding of my algorithm, I'll give you the following:
The menu div:
<div id="services_menu" class="services_menu">
...
</div>
The "services" button:
<td><a href="#" onclick="displayMenu('services'); return false;"><img src="services.jpg" border=0></a></td>
The displayMenu() function:
function displayMenu(menu)
{
var menuName = menu + "_menu";
document.getElementById(menuName).style.display = "block";
if (itemCount(menuName) >= 12)
{
enableScrolling(menuName);
}
else
{
disableScrolling(menuName);
}
}
The itemCount() function:
function itemCount(menuName)
{
var menu = document.getElementById(menuName);
var divArray = menu.getElementsByTagName("div");
return divArray.length;
}
And the enableScrolling() function I already posted above.
So essentially, when the user clicks on "service", the services menu becomes visible. If the menu contains 12 items or more, scrolling needs to be enabled. This entails setting the menu to a fixed height and allowing the user to scroll through it (scrolling, in this case, will be customized--I'm not using the div's native scrolling feature).
The really odd thing is that in itemCount(), I have exactly the same line:
var menu = document.getElementById(menuName);
and it works fine there. Why not in my enableScrolling() function?
I have a website that I need help with. You can visit it here: http://www.shahspace.com/bow/home.html. To see what I need help with, click on the services menu item and observe the alert message that comes up. It should say "point 1".
Here is the code that executes that:
function enableScrolling(menuName)
{
alert("point 1");
var menu = document.getElemenetById(menuName);
alert("point 2");
...
}
As you can see, there should be a second alert message that says "point 2", but there isn't. The script is crash when I try to assign to menu the object returned by document.getElementById(menuName). I have verified that menuName is correct. So why would this be crashing?
To get a fuller understanding of my algorithm, I'll give you the following:
The menu div:
<div id="services_menu" class="services_menu">
...
</div>
The "services" button:
<td><a href="#" onclick="displayMenu('services'); return false;"><img src="services.jpg" border=0></a></td>
The displayMenu() function:
function displayMenu(menu)
{
var menuName = menu + "_menu";
document.getElementById(menuName).style.display = "block";
if (itemCount(menuName) >= 12)
{
enableScrolling(menuName);
}
else
{
disableScrolling(menuName);
}
}
The itemCount() function:
function itemCount(menuName)
{
var menu = document.getElementById(menuName);
var divArray = menu.getElementsByTagName("div");
return divArray.length;
}
And the enableScrolling() function I already posted above.
So essentially, when the user clicks on "service", the services menu becomes visible. If the menu contains 12 items or more, scrolling needs to be enabled. This entails setting the menu to a fixed height and allowing the user to scroll through it (scrolling, in this case, will be customized--I'm not using the div's native scrolling feature).
The really odd thing is that in itemCount(), I have exactly the same line:
var menu = document.getElementById(menuName);
and it works fine there. Why not in my enableScrolling() function?