Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 543
  • Last Modified:

javascript file onmouseout

Hi,
I'm trying to modify a javascript menu so that once the mouse leaves it, it will close.  The script I'm using along with an example can be found here: http://javascript.internet.com/navigation/cascade-menu.html .

I added this part to it: menuItem.onmouseout= new Function("HideMenu(menuBar)")... but it doesn't seem to help any....

thanks
function InitMenu()
   {
     var bar = menuBar.children     
 
     for(var i=0;i < bar.length;i++) 
        {
          var menu=eval(bar[i].menu)
          menu.style.visibility = "hidden"
          bar[i].onmouseover = new Function("ShowMenu("+bar[i].id+")")
          var Items = menu.children
          for(var j=0; j<Items.length; j++)
            {
              var menuItem = eval(Items[j].id)
                
                if(menuItem.menu != null)
                   { 
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    //var tmp = eval(menuItem.id+"_Arrow")
                    // tmp.style.pixelLeft = menu.getBoundingClientRect().Right //- tmp.offsetWidth - 15
                    FindSubMenu(menuItem.menu)}
               
                 if(menuItem.cmd != null) 
                   {
                   menuItem.onclick = new Function("Do("+menuItem.id+")") } 
                   
              menuItem.onmouseover = new Function("highlight("+Items[j].id+")")
              menuItem.onmouseout= new Function("HideMenu(menuBar)")
 
            }    
        	
        }  
   }
   
   function FindSubMenu(subMenu)
   {
         var menu=eval(subMenu)
         var Items = menu.children
          for(var j=0; j<Items.length; j++)
            {
              menu.style.visibility = "hidden"
              var menuItem = eval(Items[j].id)
              
              
              if(menuItem.menu!= null)
                 {
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    // var tmp = eval(menuItem.id+"_Arrow")
                    //tmp.style.pixelLeft = 35 //menuItem.getBoundingClientRect().right - tmp.offsetWidth - 15
                    FindSubMenu(menuItem.menu)
                 }
 
                 if(menuItem.cmd != null) 
                   {
                   menuItem.onclick = new Function("Do("+menuItem.id+")") } 
                  
              menuItem.onmouseover = new Function("highlight("+Items[j].id+")")
                 
            }  
   } 
   function ShowMenu(obj)
   {
     HideMenu(menuBar)
     var menu = eval(obj.menu)
     var bar = eval(obj.id)
     bar.className="barOver"
     menu.style.visibility = "visible"
     menu.style.pixelTop =  obj.getBoundingClientRect().top + obj.offsetHeight + Bdy.scrollTop
     menu.style.pixelLeft = obj.getBoundingClientRect().left + Bdy.scrollLeft
   }
   
   function highlight(obj)
   {
     var PElement = eval(obj.parentElement.id)
     if(PElement.hasChildNodes() == true)
     {  var Elements = PElement.children
       for(var i=0;i<Elements.length;i++)
       {
          TE = eval(Elements[i].id)
          TE.className = "menuItem"
       }
      } 
     obj.className="ItemMouseOver"
     window.defaultStatus = obj.title
     ShowSubMenu(obj)
   }
   
   function Do(obj)
   {
    var cmd = eval(obj).cmd	
    window.navigate(cmd)
     
   }
   
   function HideMenu(obj)
   {
          if(obj.hasChildNodes()==true)
              {  
                 var child = obj.children     
                 
                 for(var j =0;j<child.length;j++)
                  {
                     if (child[j].className=="barOver")
                     {var bar = eval(child[j].id)
                      bar.className="Bar"}
                      
                     if(child[j].menu != null)
                       {
                          var childMenu = eval(child[j].menu)
                          if(childMenu.hasChildNodes()==true) 
                               HideMenu(childMenu)
                          
                           childMenu.style.visibility = "hidden" 
                         }
                  }
              
              }
   }
  function ShowSubMenu(obj)
  {
     PMenu = eval(obj.parentElement.id)
      HideMenu(PMenu)
     if(obj.menu != null)
     {
     var menu = eval(obj.menu)
     menu.style.visibility = "visible"
     menu.style.pixelTop =  obj.getBoundingClientRect().top + Bdy.scrollTop
     menu.style.pixelLeft = obj.getBoundingClientRect().right + Bdy.scrollLeft
     if(menu.getBoundingClientRect().right > window.screen.availWidth )
       menu.style.pixelLeft = obj.getBoundingClientRect().left - menu.offsetWidth
    }
  } 
 
 
 
 
 
 
 ///////////////////CascadedDropdown Menu/////////////////
 //Date : 08/09/2001               						//
 //Version : 1.0        								//
 //Author Mr.Arun N Kumar	                            //
 //EMail: n_arunk@hotmail.com							//		
 /////////////////////////////////////////////////////////
 // Modifications on this code is not recomended
 // Suggestions are welcome

Open in new window

0
tolninja
Asked:
tolninja
  • 2
  • 2
1 Solution
 
IanThCommented:
you need to use onblur

see http://www.w3schools.com/jsref/jsref_onblur.asp

onblur happens when the object loses focus
0
 
tolninjaAuthor Commented:
That doesn't have the result I'm looking for.  thanks
0
 
IanThCommented:
yes sorry its for forms really i realised afterwards
0
 
tolninjaAuthor Commented:
No problem.  thanks for trying anyway.  I found something that kind of works.  It sets a timer.  Once the mouse leaves the main menu bar a user has 3 seconds to select a child object before they disappear.  I works, but it's not a great solution.  I would rather the menu not disappear until the mouse moves off the child objects.
function InitMenu()
   {
     var bar = menuBar.children     
 
     for(var i=0;i < bar.length;i++) 
        {
          var menu=eval(bar[i].menu)
          menu.style.visibility = "hidden"
          bar[i].onmouseover = new Function("ShowMenu("+bar[i].id+");show();")
	      bar[i].onmouseout = new Function("hide();");
          var Items = menu.children
          for(var j=0; j<Items.length; j++)
            {
              var menuItem = eval(Items[j].id)
                
                if(menuItem.menu != null)
                   { 
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    FindSubMenu(menuItem.menu)}
            }    
        }  
   }
 
   	function hide()
	{
	time = window.setInterval("hide2()",3000);
	}
	
	function hide2()
	{
		HideMenu(menuBar);
		window.clearInterval(time);
	}
	
	function show()
	{
		window.clearInterval(time);
	}
	
	function nothing()
	{
		window.clearInterval(time);
	}
 
   function FindSubMenu(subMenu)
   {
         var menu=eval(subMenu)
         var Items = menu.children
          for(var j=0; j<Items.length; j++)
            {
              menu.style.visibility = "hidden"
              var menuItem = eval(Items[j].id)
              
              
              if(menuItem.menu!= null)
                 {
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    FindSubMenu(menuItem.menu)
                 }
			}
   } 
   function ShowMenu(obj)
   {
     HideMenu(menuBar)
     var menu = eval(obj.menu)
     var bar = eval(obj.id)
     bar.className="barOver"
     menu.style.visibility = "visible"
     menu.style.pixelTop =  obj.getBoundingClientRect().top + obj.offsetHeight + Bdy.scrollTop
     menu.style.pixelLeft = obj.getBoundingClientRect().left + Bdy.scrollLeft
   }
   
   function highlight(obj)
   {
     var PElement = eval(obj.parentElement.id)
     if(PElement.hasChildNodes() == true)
     {  var Elements = PElement.children
       for(var i=0;i<Elements.length;i++)
       {
          TE = eval(Elements[i].id)
          TE.className = "menuItem"
       }
      } 
     obj.className="ItemMouseOver"
     window.defaultStatus = obj.title
     ShowSubMenu(obj)
   }
 
   function HideMenu(obj)
   {
     var child = obj.children     
                 
     for(var j =0;j<child.length;j++)
      {
         if(child[j].menu != null)
           {
              var childMenu = eval(child[j].menu)
              if(childMenu.hasChildNodes()==true)
			  {
                   HideMenu(childMenu)
				   childMenu.style.visibility = "hidden" 
			  }
           }
      }
   }
   
  function ShowSubMenu(obj)
  {
     PMenu = eval(obj.parentElement.id)
      HideMenu(PMenu)
     if(obj.menu != null)
     {
     var menu = eval(obj.menu)
     menu.style.visibility = "visible"
     menu.style.pixelTop =  obj.getBoundingClientRect().top + Bdy.scrollTop
     menu.style.pixelLeft = obj.getBoundingClientRect().right + Bdy.scrollLeft
     if(menu.getBoundingClientRect().right > window.screen.availWidth )
       menu.style.pixelLeft = obj.getBoundingClientRect().left - menu.offsetWidth
    }
  } 
 
 
 
 
 
 ///////////////////CascadedDropdown Menu/////////////////
 //Date : 08/09/2001               						//
 //Version : 1.0        								//
 //Author Mr.Arun N Kumar	                            //
 //EMail: n_arunk@hotmail.com							//		
 /////////////////////////////////////////////////////////
 // Modifications on this code is not recomended
 // Suggestions are welcome

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now