Forum Moderators: open
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script language="JavaScript1.2">
function hideshow(which){
if (!document.getElementById)
return
alert(which);
if (which.style.display=="none")
which.style.display=""
else
which.style.display="none"
}
function hide(which){
if (!document.getElementById)
return
if (which.style.display=="")
which.style.display="none"
}
</script>
<div id="mainNav">
<a href="#" id="mainNav 1" onClick="javascript:hideshow(document.getElementById('firstSubMenu'))">SORTIMENT</a>
<a href="#" id="mainNav 2" onClick="javascript:hide(document.getElementById('firstSubMenu'))">BUTIKEN</a>
<a href="#" id="mainNav 3" onClick="javascript:hide(document.getElementById('firstSubMenu'))">LEVERANTÖRER</a>
<a href="#" id="mainNav 4" onClick="javascript:hide(document.getElementById('firstSubMenu'))">KONTAKTA OSS</a>
<a href="#" id="mainNav 5" onClick="javascript:hide(document.getElementById('firstSubMenu'))">STARTSIDA</a>
</div>
<div id="firstSubMenu" style="display:none;">
<a href="#" id="FSub 1" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 1</a>
<a href="#" id="FSub 2" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 2</a>
<a href="#" id="FSub 3" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 3</a>
<a href="#" id="FSub 4" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 4</a>
<a href="#" id="FSub 5" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 5 </a>
<a href="#" id="FSub 6" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 6</a>
<a href="#" id="FSub 7" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 7</a>
<a href="#" id="FSub 8" onClick="javascript:hideshow(document.getElementById('secondSubMenu'))">FSub 8</a>
</div>
<div id="secondSubMenu" style="display:none;">
<a href="#" id="SSub 1">SSub 1</a>
<a href="#" id="SSub 2">SSub 2</a>
<a href="#" id="SSub 3">SSub 3</a>
<a href="#" id="SSub 4">SSub 4</a>
<a href="#" id="SSub 5">SSub 5</a>
</div>
</body>
</html>
<body>
<script language="JavaScript1.2">
function hideshow(which){
if (!document.getElementById)
return ;
if (which.style.display=="none")
which.style.display="" ;
else
which.style.display="none" ;
}
function hide(which){
if (!document.getElementById)
return
if (which.style.display=="")
which.style.display="none" ;
}
</script>
<div id="mainNav">
<a href="#" id="mainNav 1" onClick="javascript:hideshow(document.getElementById('firstSubMenu'));hide(document.getElementById('secondSubMenu'))">SORTIMENT</a>
<a href="#" id="mainNav 2" onClick="javascript:hide(document.getElementById('firstSubMenu'));hide(document.getElementById('secondSubMenu'))">BUTIKEN</a>
<a href="#" id="mainNav 3" onClick="javascript:hide(document.getElementById('firstSubMenu'));hide(document.getElementById('secondSubMenu'))">LEVERANTÖRER</a>
<a href="#" id="mainNav 4" onClick="javascript:hide(document.getElementById('firstSubMenu'));hide(document.getElementById('secondSubMenu'))">KONTAKTA OSS</a>
<a href="#" id="mainNav 5" onClick="javascript:hide(document.getElementById('firstSubMenu'));hide(document.getElementById('secondSubMenu'))">STARTSIDA</a>
</div>
<div id="firstSubMenu" style="display:none;">
<a href="#" id="FSub 1" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 1</a>
<a href="#" id="FSub 2" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 2</a>
<a href="#" id="FSub 3" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 3</a>
<a href="#" id="FSub 4" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 4</a>
<a href="#" id="FSub 5" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 5 </a>
<a href="#" id="FSub 6" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 6</a>
<a href="#" id="FSub 7" onClick="javascript:hide(document.getElementById('secondSubMenu'))">FSub 7</a>
<a href="#" id="FSub 8" onClick="javascript:hideshow(document.getElementById('secondSubMenu'))">FSub 8</a>
</div>
<div id="secondSubMenu" style="display:none;">
<a href="#" id="SSub 1">SSub 1</a>
<a href="#" id="SSub 2">SSub 2</a>
<a href="#" id="SSub 3">SSub 3</a>
<a href="#" id="SSub 4">SSub 4</a>
<a href="#" id="SSub 5">SSub 5</a>
</div>
</body>
</html>
onClick="javascript:hide(document.getElementById('secondSubMenu'))" There's a fair amount of this going on, and you could do away with most of it.
1.
javascript: Use of this pseudo-protocol is unnecessary in an event handler.
That can go.
2. document.getElementById(....)
There is a test for support of this method inside the functions that are called. If the method is not supported
(IE4 & NS4), then the error would have already occurred in the event handler.
IMHO, for this reason, and to make the code shorter, it would be better to put this part inside the functions...
onClick="hide('secondSubMenu')"
then
function hideshow(id){
if (document.getElementById)
var which = document.getElementById(id)
else
return;
if (which.style.display=="none")
..etc..