Solved

javascript onmouseout hide submenu help

Posted on 2004-04-14
8
2,684 Views
Last Modified: 2007-12-19
Hi,

I need help implementing onMouseOut hide submenu for the following menu script that another expert(Lisa) has helped me implement.

Right now she has implemented onClick hide, but I tried to implement onMouseOut but it seems not to work.

here is the code below.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
     <HEAD>
     
      <Script language='JavaScript'>
     function SubMenu(Cell){
          switch (Cell)
          {
          case "S0":{
          var elem = document.getElementById("S1");
          elem.style.visibility = 'hidden'
         
          }
          break
          case "S1":{
            var parent = document.getElementById("T1");
            var x = getRealLeft(parent);
            var y = getRealTop(parent);
           
          var elem = document.getElementById("S1");
            elem.style.position = "absolute";
            elem.style.left = x + 151; //width attribute of parent menu table + 1
            elem.style.top = y;
          elem.style.visibility = 'visible'
         
          }
          break
     
     }
}

function HideSub()
     {
     SubMenu("S0");
     return true;
     }

window.onclick=HideSub;
document.onclick=HideSub;

</Script>
         
     </HEAD>
     <body>
     
      <P>
                   
<script language="javascript">
//// FUNCTIONS TO POPUP AND SWAP MENU ITEMS
function Hide(Cell){
     Cell.style.visibility = "hidden"
      }
function Show(Cell)
     {
      Cell.style.visibility = "visible"
     }

function Swap(Cell){
     //alert("Swap" + Cell.id);
     switch (Cell.style.color){
     case "":
     {
     Cell.style.color="white"
     Cell.style.background="steelblue"
     }
     break
     case "white":
     {
     Cell.style.color=""
     Cell.style.background="whitesmoke"
     }
     break
     default:
     Cell.style.visibility = "hidden"
     }
}

function NavTo(Loc){
     window.location = Loc
     }
     
function getRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}

     
</script>

<TABLE  onMouseOver=SubMenu('S1');Swap(this) onMouseOut=Swap(this) class='Menu' id='T1'
     style='Z-INDEX: 1;' cellSpacing='0' cellPadding='3' width='150' height='20'  border='0'>
     <TR>
          <TD title='Menu 1'>Menu 1</TD>
     </TR>
</TABLE>
          <TABLE class='SubMenu' id='S1' style='visibility: hidden; Z-INDEX: 2;cellSpacing='0' cellPadding='3' width='150' border='0'>
               <TR>
               <TD title='SubMenu 1-2' height='20'onMouseOver=Swap(this) onMouseOut=Swap(this) width='100%' onClick=NavTo('index.aspx')>SubMenu 1-2</TD>
               </TR>
               <TR>
               <TR>
               <TD title='SubMenu 1-3' height='20'onMouseOver=Swap(this) onMouseOut=Swap(this) width='100%' onClick=NavTo('index.aspx')>SubMenu 1-3</TD>
               </TR>
               <TR>
               <TR>
               <TD title='SubMenu 1-4' height='20'onMouseOver=Swap(this) onMouseOut=Swap(this) width='100%' onClick=NavTo('index.aspx')>SubMenu 1-4</TD>
               </TR>
               <TR>
               <TR>
               <TD title='SubMenu 1-5' height='20'onMouseOver=Swap(this) onMouseOut=Swap(this) width='100%' onClick=NavTo('index.aspx')>SubMenu 1-5</TD>
               </TR>
          </TABLE>


     </body>
</HTML>

I only have 125 points left. sorry.

thanks.
0
Comment
Question by:sheikhhasan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:sheikhhasan
ID: 10824234
Also the onMouseOver and onMouseOut change text color and background is kind of weird, color change does not go out onMouseOut. Any help with that would be appreciated also.
0
 

Author Comment

by:sheikhhasan
ID: 10824428
I was able to fix the mouseover hide menu. :)

0
 
LVL 3

Expert Comment

by:ljfernandez
ID: 10824988
Glad you got the hide menu onmouseover to work.

I don't understand what the other problem is. The color seems to change correctly for me, from steelblue to whitesmoke, although originally there is no background color. If you are still having the problem, please explain.

Lisa
0
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!

 

Author Comment

by:sheikhhasan
ID: 10825467
Hi

http://208.202.161.42/idmextranet/menu/index.aspx 

this is the link to the menu, any idea how to fix the space between the menu items? Once you rollover they get fixed.
0
 
LVL 3

Expert Comment

by:ljfernandez
ID: 10825742
Add position:absolute to the style of the submenu tables like so (put spaces between the tag attributes for clarity):

<TABLE
     class='SubMenu'
     id='S1'
     onMouseOver=SubMenu('S1');Swap(this)
     onMouseOut=Swap(this);SubMenu('S0')

     style='position:absolute;border: 1px solid gray; visibility: hidden; Z-INDEX: 2;'

     cellSpacing='0'
     cellPadding='0'
     width='100'>

--Lisa
0
 

Author Comment

by:sheikhhasan
ID: 10826172
thank you so much
0
 
LVL 3

Accepted Solution

by:
ljfernandez earned 125 total points
ID: 10826921
So do I get the points then?
0
 

Author Comment

by:sheikhhasan
ID: 10827419
the points are all yours.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question