nicolanicola
07-09-2009, 04:57 PM
I am making a drop down menu in javascript using a function in an external js file. Problem is in FF error console it keeps coming up that my ID that's being called in getElementByID in the function is not defined.
Am tearing my hair out. I am quite a newbie to all this so nothing too complicated please!! Just wondering why it is reading the ID name when it is passed into it when the function is called.
HTML:
<div id="menu_nav">
<div id="home" class="flMen"><a href="index.html" onmouseover="showSubMenu(homeSubMenu)">HOME ></a></div>
<div id="services" class="flMen"><a href="services.html" onmouseover="showSubMenu(servicesSubMenu)">SERVICES ></a></div>
<div id="portfolio" class="flMen"><a href="portfolio.html">PORTFOLIO ></a></div>
<div id="class" class="flMen"><a href="about.html">ABOUT ></a></div>
</div>
<div id="homeSubMenu" class="flMen">
</div>
<div id="servicesSubMenu" class="flMen">
<div><a href="video.html">Video ></a></div>
</div>
In the css I have marked servicesSubMenu as display:none.
Here is JS
function showSubMenu(chosenMenu)
{
alert("hi")
var submenu=document.getElementById(chosenMenu);
if(submenu.style.display=="block")
{
submenu.style.display="none"
}else{
submenu.style.display="block"
}
}
Please help if you can, why is saying my ID is undefined?????
Am tearing my hair out. I am quite a newbie to all this so nothing too complicated please!! Just wondering why it is reading the ID name when it is passed into it when the function is called.
HTML:
<div id="menu_nav">
<div id="home" class="flMen"><a href="index.html" onmouseover="showSubMenu(homeSubMenu)">HOME ></a></div>
<div id="services" class="flMen"><a href="services.html" onmouseover="showSubMenu(servicesSubMenu)">SERVICES ></a></div>
<div id="portfolio" class="flMen"><a href="portfolio.html">PORTFOLIO ></a></div>
<div id="class" class="flMen"><a href="about.html">ABOUT ></a></div>
</div>
<div id="homeSubMenu" class="flMen">
</div>
<div id="servicesSubMenu" class="flMen">
<div><a href="video.html">Video ></a></div>
</div>
In the css I have marked servicesSubMenu as display:none.
Here is JS
function showSubMenu(chosenMenu)
{
alert("hi")
var submenu=document.getElementById(chosenMenu);
if(submenu.style.display=="block")
{
submenu.style.display="none"
}else{
submenu.style.display="block"
}
}
Please help if you can, why is saying my ID is undefined?????