J
joejodihurley
Trying to do a very simple dropdown menu using CSS...a horizontal menu
with vertical dropdowns. Works perfectly in Firefox, but not so in
IE7 (imagine my frustration). I have slimmed down the program to the
lowest form possible. Essentially, it will work in both browsers when
the list is NOT an entry in a table, but will NOT work in IE if it is
in a table format. Firefox obviously accepts both formats.
I am relatively new to javascript and CSS, so I apologize if this is
an easy fix. I have spent nearly 2 weeks playing with things, and a
solution is not coming to me. I believe it is not in the javascript,
but how the CSS properties talk with IE????
Here is the the entire file...removing the commented HTML code in the
body will make it work fine in both browsers, but due to the other
code not shown, I need it to be in a table format. Thank you all in
advance for your help.
<html>
<head>
<!--
*******************************************************************************************************
-->
<!-- ************************************START OF JAVASCRIPT
************************************* -->
<!--
*******************************************************************************************************
-->
<script language="javascript" type="text/javascript">
var t=false,current;
function SetupMenu() {
if (!document.getElementsByTagName) return;
items=document.getElementsByTagName("li");
for (i=0; i<items.length; i++) {
if (items.className != "menu") continue;
thelink=findChild(items,"A");
thelink.onmouseover=ShowMenu;
thelink.onmouseout=StartTimer;
if (ul=findChild(items,"UL")) {
ul.style.display="none";
for (j=0; j<ul.childNodes.length; j++) {
ul.childNodes[j].onmouseover=ResetTimer;
ul.childNodes[j].onmouseout=StartTimer;
}
}
}
}
function findChild(obj,tag) {
cn = obj.childNodes;
for (k=0; k<cn.length; k++) {
if (cn[k].nodeName==tag) return cn[k];
}
return false;
}
function ShowMenu(e) {
if (!e) var e = window.event;
thislink = (e.target) ? e.target: e.srcElement;
ResetTimer();
if (current) HideMenu(current);
thislink = thislink.parentNode;
current=thislink;
ul = findChild(thislink,"UL");
if (!ul) return;
ul.style.display="block";
}
function HideMenu(thelink) {
ul = findChild(thelink,"UL");
if (!ul) return;
ul.style.display="none";
}
function ResetTimer() {
if (t) window.clearTimeout(t);
}
function StartTimer() {
t = window.setTimeout("HideMenu(current)",200);
}
window.onload=SetupMenu;
</script>
<!--
*******************************************************************************************************
-->
<!-- ***********************END OF JAVASCRIPT, START OF CSS
******************************** -->
<!--
*******************************************************************************************************
-->
<style type="text/css">
#menu {
position: absolute;
font-family: "GoudyOlSt BT", sans-serif;
font-size: 15;
}
#menu li {
float: left;
list-style-type: none;
width: 140px;
position: relative;
background-color: white;
border: none;
margin-left: 0px;
font-weight: bold;
}
#menu li a{
color: black;
text-decoration: none;
width: 100%;
display: block;
}
#menu li a:hover {
color: black;
}
#menu li ul {
background-color: white;
margin: 0px;
padding: 0px;
}
#menu li ul li {
padding: 0px;
margin: 0px;
float: none;
list-style-type: none;
width: 140px;
text-indent: 10px;
border: 1px solid black;
font-weight: none;
}
#menu li ul li a{
color: black;
text-decoration: none;
}
#menu li ul li a:hover{
background-color: black;
color: white;
}
</style>
<!--
*******************************************************************************************************
-->
<!-- ************************END OF CSS/HEAD, START OF
BODY******************************** -->
<!--
*******************************************************************************************************
-->
</head>
<body bgcolor="9C9C9C">
<table> <!-- Will work in IE7 if removed -->
<tr> <!-- Will work in IE7 if removed -->
<td> <!-- Will work in IE7 if removed -->
<ul id="menu">
<li class="menu"><a href="#">Item1</a>
<ul>
<li><a href="#">SubItem1-1</a></li>
<li><a href="#">SubItem1-2</a></li>
<li><a href="#">SubItem1-3</a></li>
</ul>
</li>
<li class="menu"><a href="#">Item2</a>
<ul>
<li><a href="#">SubItem2-1</a></li>
<li><a href="#">SubItem2-2</a></li>
<li><a href="#">SubItem2-3</a></li>
<li><a href="#">SubItem2-4</a></li>
</ul>
</li>
<li class="menu"><a href="#">Item3</a>
<ul>
<li><a href="#">SubItem3-1</a></li>
<li><a href="#">SubItem3-2</a></li>
</ul>
</li>
<li class="menu"><a href="#">Item4</a>
<ul>
<li><a href="#">SubItem4-1</a></li>
<li><a href="#">SubItem4-2</a></li>
</ul>
</li>
</ul>
</td> <!-- Will work in IE7 if removed -->
</tr> <!-- Will work in IE7 if removed -->
</table> <!-- Will work in IE7 if removed -->
</body>
</html>
with vertical dropdowns. Works perfectly in Firefox, but not so in
IE7 (imagine my frustration). I have slimmed down the program to the
lowest form possible. Essentially, it will work in both browsers when
the list is NOT an entry in a table, but will NOT work in IE if it is
in a table format. Firefox obviously accepts both formats.
I am relatively new to javascript and CSS, so I apologize if this is
an easy fix. I have spent nearly 2 weeks playing with things, and a
solution is not coming to me. I believe it is not in the javascript,
but how the CSS properties talk with IE????
Here is the the entire file...removing the commented HTML code in the
body will make it work fine in both browsers, but due to the other
code not shown, I need it to be in a table format. Thank you all in
advance for your help.
<html>
<head>
<!--
*******************************************************************************************************
-->
<!-- ************************************START OF JAVASCRIPT
************************************* -->
<!--
*******************************************************************************************************
-->
<script language="javascript" type="text/javascript">
var t=false,current;
function SetupMenu() {
if (!document.getElementsByTagName) return;
items=document.getElementsByTagName("li");
for (i=0; i<items.length; i++) {
if (items.className != "menu") continue;
thelink=findChild(items,"A");
thelink.onmouseover=ShowMenu;
thelink.onmouseout=StartTimer;
if (ul=findChild(items,"UL")) {
ul.style.display="none";
for (j=0; j<ul.childNodes.length; j++) {
ul.childNodes[j].onmouseover=ResetTimer;
ul.childNodes[j].onmouseout=StartTimer;
}
}
}
}
function findChild(obj,tag) {
cn = obj.childNodes;
for (k=0; k<cn.length; k++) {
if (cn[k].nodeName==tag) return cn[k];
}
return false;
}
function ShowMenu(e) {
if (!e) var e = window.event;
thislink = (e.target) ? e.target: e.srcElement;
ResetTimer();
if (current) HideMenu(current);
thislink = thislink.parentNode;
current=thislink;
ul = findChild(thislink,"UL");
if (!ul) return;
ul.style.display="block";
}
function HideMenu(thelink) {
ul = findChild(thelink,"UL");
if (!ul) return;
ul.style.display="none";
}
function ResetTimer() {
if (t) window.clearTimeout(t);
}
function StartTimer() {
t = window.setTimeout("HideMenu(current)",200);
}
window.onload=SetupMenu;
</script>
<!--
*******************************************************************************************************
-->
<!-- ***********************END OF JAVASCRIPT, START OF CSS
******************************** -->
<!--
*******************************************************************************************************
-->
<style type="text/css">
#menu {
position: absolute;
font-family: "GoudyOlSt BT", sans-serif;
font-size: 15;
}
#menu li {
float: left;
list-style-type: none;
width: 140px;
position: relative;
background-color: white;
border: none;
margin-left: 0px;
font-weight: bold;
}
#menu li a{
color: black;
text-decoration: none;
width: 100%;
display: block;
}
#menu li a:hover {
color: black;
}
#menu li ul {
background-color: white;
margin: 0px;
padding: 0px;
}
#menu li ul li {
padding: 0px;
margin: 0px;
float: none;
list-style-type: none;
width: 140px;
text-indent: 10px;
border: 1px solid black;
font-weight: none;
}
#menu li ul li a{
color: black;
text-decoration: none;
}
#menu li ul li a:hover{
background-color: black;
color: white;
}
</style>
<!--
*******************************************************************************************************
-->
<!-- ************************END OF CSS/HEAD, START OF
BODY******************************** -->
<!--
*******************************************************************************************************
-->
</head>
<body bgcolor="9C9C9C">
<table> <!-- Will work in IE7 if removed -->
<tr> <!-- Will work in IE7 if removed -->
<td> <!-- Will work in IE7 if removed -->
<ul id="menu">
<li class="menu"><a href="#">Item1</a>
<ul>
<li><a href="#">SubItem1-1</a></li>
<li><a href="#">SubItem1-2</a></li>
<li><a href="#">SubItem1-3</a></li>
</ul>
</li>
<li class="menu"><a href="#">Item2</a>
<ul>
<li><a href="#">SubItem2-1</a></li>
<li><a href="#">SubItem2-2</a></li>
<li><a href="#">SubItem2-3</a></li>
<li><a href="#">SubItem2-4</a></li>
</ul>
</li>
<li class="menu"><a href="#">Item3</a>
<ul>
<li><a href="#">SubItem3-1</a></li>
<li><a href="#">SubItem3-2</a></li>
</ul>
</li>
<li class="menu"><a href="#">Item4</a>
<ul>
<li><a href="#">SubItem4-1</a></li>
<li><a href="#">SubItem4-2</a></li>
</ul>
</li>
</ul>
</td> <!-- Will work in IE7 if removed -->
</tr> <!-- Will work in IE7 if removed -->
</table> <!-- Will work in IE7 if removed -->
</body>
</html>