Jump to content

Show/Hide Multiple Objects (onMouseOver/Out)


Somebody's Fat

Recommended Posts

I'm essentially looking for any assistance regarding this issue. I'm by no means an expert of javascript.Bottom line: I'm creating a website with various menus that are visible/hidden depending upon rollover of a certain <td> area (Example below is "News"). The visible <table> then appears in 2 locations (I need them in 2 locations because I need an active mouseOut area that is NOT a perfect rectangle. This way, it avoids covering the active area of "Entertainment" up, etc.)MenuJavaHelp.gifI would love to use this as a script:

function showmenu(elmnt){document.getElementById(elmnt).style.visibility="visible"}function hidemenu(elmnt){document.getElementById(elmnt).style.visibility="hidden"}

Making the ID tags for the 2 tables change values to visible/hidden depending on the rollover. I was hoping this would work for the <td>:

onmouseover="showmenu('NewsBox','NewsMenu')" onmouseout="hidemenu('NewsBox','NewsMenu')"

...given "NewsBox" was the id for table 1 and "NewsMenu" the id for table 2.Unhappily, this didn't work. Why... I don't even know. I ended up doing this:

onmouseover="showmenu('NewsBox'),NewsMenuShow()" onmouseout="hidemenu('NewsBox'),NewsMenuHide()"

Where "NewsMenu" had its own function for changing visibility. This worked in IE. Firefox didn't like it. After some more troubleshooting, I found that if I removed this from my html file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

Then it DID work in Firefox. Anyway, at this point, I'm lost. I'd like to keep the DOCTYPE in the file, but I need the menus to work in all browsers. Perhaps I'm going about this all wrong and there's an easier way that I don't know about. If anyone can help, I'm all ears... or eyes I should say.

Link to comment
Share on other sites

onmouseover="showmenu('NewsBox','NewsMenu')" onmouseout="hidemenu('NewsBox','NewsMenu')"

The above method should work ok, it probably didnt work because you were trying to pass two values to functions that only accepted one paramenter, change both functions to accept two values and it should work ok.

function showmenu(elmnt1,elmnt2){document.getElementById(elmnt1).style.visibility="visible";document.getElementById(elmnt2).style.visibility="visible";}function hidemenu(elmnt1,elmnt2){  document.getElementById(elmnt1).style.visibility="hidden";  document.getElementById(elmnt2).style.visibility="hidden";}

Link to comment
Share on other sites

Thanks Scott! I gave that a try and it works fine in all browsers.Just a couple questions to clarify my understanding of it... I basically found "getElementById(elmnt)" by looking up various menus and examples I had found elsewhere on the web. Is "elmnt" a standard abbreviation for something like this, or was it just what I had obtained from someone's example? Same question for getElementById... I'm guessing that's standard code for referencing various elements by ID? And lastly...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

Could someone explain why the usage or non-usage of this line of code was affecting the appearance and functionality of my scripts? Is it most beneficial to use "strict.dtd" as opposed to "loose.dtd"? (My website is heavily HTML/CSS with JavaScript, no frames, just iframes.)

Link to comment
Share on other sites

Just a couple questions to clarify my understanding of it... I basically found "getElementById(elmnt)" by looking up various menus and examples I had found elsewhere on the web.  Is "elmnt" a standard abbreviation for something like this, or was it just what I had obtained from someone's example?  Same question for getElementById... I'm guessing that's standard code for referencing various elements by ID?  And lastly...

elmnt is just a word chosen by that programmer. you could use what you want:
function showmenu(fish,chips){document.getElementById(fish).style.visibility="visible";document.getElementById(chips).style.visibility="visible";}function hidemenu(fish,chips){ document.getElementById(fish).style.visibility="hidden"; document.getElementById(chips).style.visibility="hidden";}

document.getElementById = get the element in this document using the id i give you.there are other ways you can access elements:document.getElementsByNamedocument.getElementByClass

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...