Forum Moderators: open

Message Too Old, No Replies

toggle menu in multiple browsers

         

bingymon

1:27 am on Nov 9, 2003 (gmt 0)

10+ Year Member



I'm trying to get his little toggle menu script to run in multiple browsers without any luck. Can anyone suggest a workaround? It works for me in IE6 but mozilla doesn't like it.

<HTML>
<HEAD>
<TITLE>toggle foo</TITLE>
<SCRIPT TYPE="TEXT/JAVASCRIPT" LANGUAGE=JAVASCRIPT>
<!-- Hide script from older browsers
function toggleMenu(currMenu) {
if (document.all) {
thisMenu = eval("document.all." + currMenu + ".style")
if (thisMenu.display == "block") {
thisMenu.display = "none"
}
else {
thisMenu.display = "block"
}
return false
}
else {
return true
}
}
// End hiding script -->
</SCRIPT>
<STYLE TYPE="TEXT/CSS">
#menu1 {display:none; margin-left:20px}

</STYLE>
</HEAD>
<BODY BGCOLOR=WHITE>
<H3>
<A HREF="#" onClick="return toggleMenu('menu1')">Toggle Me</A>
</H3>
<SPAN ID="menu1">
heres my text to display <BR>
heres my text to display<BR>
heres my text to display<BR>
heres my text to display
</SPAN>
<H3>other stuff<h3>
</BODY>
</HTML>

birdbrain

6:29 pm on Nov 9, 2003 (gmt 0)



Hi there bingymon,

The problem here, seems to be with 'all' and 'eval' so remove...

{
if (document.all) {
thisMenu = eval("document.all." + currMenu + ".style")

and replace it with...

{
if(document.getElementById('menu1'))
{
thisMenu = document.getElementById('menu1').style;

birdbrain

bingymon

4:53 am on Nov 10, 2003 (gmt 0)

10+ Year Member



Hey thanks birdbrain -- that worked perfectly!

DrDoc

4:17 pm on Nov 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...and now it won't work in older versions of IE ;)