PDA

View Full Version : Issue with DD sideMenuBar



jdadwilson
05-28-2014, 10:01 PM
I have long been a user of the DD sideMenuBar for several of my sites. Recently I noticed that it throws an error at the following line:


var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")

Not knowing that much about javascript it appears that the problem is that I sometimes have only one or two levels declared but the script is looking for three levels.

Is there a work-around for this? It is not a showstopper but is really annoying when testing.

jdadwilson

jscheuer1
05-29-2014, 12:47 AM
Please post about Dynamic Drive Scripts in the Dynamic Drive Scripts Help section here where I've moved this thread, and:

Warning: Please include a link to the DD script(s) in question in your post. See this post (http://www.dynamicdrive.com/forums/showpost.php?p=7) for more information.

This sort of problem is usually due to declaring more menus and/or sub menus than you realize.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

jdadwilson
05-29-2014, 01:13 AM
Here is a link to a page that gets the error...

[URL="http://www.txfannin.org/census.php[/URL]

Using sideBarMenu in this instance I would assume that I would only need one declaration in the script.


var menuids=["sidebarmenu1"]

But since I use the script across multiple pages where I might have two or three sub menus, don't I need to declare all of them?

Thanks for your assistance...
jdadwilson

jscheuer1
05-29-2014, 01:52 PM
Change:


var menuids=["sidebarmenu1", "sidebarmenu2", "sidebarmenu3"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas

to:


var menuids=["sidebarmenu1"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas

That will fix that one menu.

The browser cache may need to be cleared and/or the page refreshed to see changes.

If you have different menus with more or less menuids on different pages all using the same external script, instead of declaring this variable in the external script, declare it on each page before the external tag to the Side Menu Bar script. that would mean, removing:


var menuids=["sidebarmenu1", "sidebarmenu2", "sidebarmenu3"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas

from the script and, for example on the page you linked to (census.php) add the highlighted:


<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="files_java/jquery.dataTables.1.09.4.min.js"></script>
<script type="text/javascript" src="files_java/jquery.dataTables.tableTools.2.2.1-dev.js"></script>
<script type="text/javascript" src="files_java_mine/site_functions.js"></script>
<script type="text/javascript" src="files_java/jquery.functions.js"></script>
<script type="text/javascript">
var menuids=["sidebarmenu1"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas
</script>
<script type="text/javascript" src="files_java/sideBarMenu.js"></script>
<script type="text/javascript" src="files_java/equalcolumns.js"></script>

<script type="text/javascript" src="files_java/tableRowHilite.js"></script>

OR you could use this modified version of the script:



// Nested Side Bar Menu (Mar 20th, 09)
// By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["sidebarmenu1", "sidebarmenu2", "sidebarmenu3"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas

function initsidebarmenu()
{
for (var i=0; i<menuids.length; i++)
{
if(document.getElementById(menuids[i]))
{
var ultags = document.getElementById(menuids[i]).getElementsByTagName("ul")
for (var t=0; t<ultags.length; t++)
{
ultags[t].parentNode.getElementsByTagName("a")[0].className+=" subfolderstyle"
if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
//dynamically position first level submenus to be width of main menu item
ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px"
else //else if this is a sub level submenu (ul)
//position menu to the right of menu item that activated it
ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px"
ultags[t].parentNode.onmouseover=function()
{
this.getElementsByTagName("ul")[0].style.display="block"
}
ultags[t].parentNode.onmouseout=function()
{
this.getElementsByTagName("ul")[0].style.display="none"
}
}
//loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
for (var t=ultags.length-1; t>-1; t--)
{
ultags[t].style.visibility="visible"
ultags[t].style.display="none"
}
}
}
}

if (window.addEventListener)
window.addEventListener("load", initsidebarmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", initsidebarmenu)