---
title: "Meny fel?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/100768-meny-fel"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "Bosse168"
published: "2004-04-01T16:26:34.000Z"
updated: "2004-04-01T21:03:51.000Z"
replies: 1
views: 183
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/100768-meny-fel"
---

# Meny fel?

## #1 — Bosse168, 2004-04-01T16:26Z

Får inte min meny att fungera som jag vill.
Problemet är att den tidigare meny klickningen inte döljs när man klickar på en ny huvud meny och att den visar fel underkategori och ibland 2. Någon som vet vad det kan vara för fel?

```
<html>
<head>
<style type="text/css">
a { text-decoration: none; color: #000000; FONT-WEIGHT: bolder }
a.klickad { text-decoration: none; color: FFFFFF; FONT-WEIGHT: bolder }

td           { font-size: 8pt; color: #000000; font-family: verdana }
a:hover      { text-decoration: none; color: #FFFFFF; FONT-WEIGHT: bolder }

tr#sub1 td table,tr#sub2 td table,tr#sub3 td table{
margin-left : 0px;
}
tr#sub1,tr#sub2,tr#sub3{
display : none;
}
-->
</style>
<script type="text/javascript">
function klicka(theLink){
    for(var i=0; i<document.links.length; i++){
        document.links[i].className="";
    }
    theLink.className="klickad";
}
//--------------------------->

var active=null,_oE=null;
var subMenus=[
	["sub1","cat","Meny 1 sub"],
	["sub2","cat","Meny 2 sub"],
	["sub3","cat","Meny 3 sub"],
];

function getElm(e){
	switch(true){
	case typeof(document.all)=="object":
		return document.all[e];
	case typeof(document.getElementById)=="function":
		return document.getElementById(e);
	default:
		return null;
	}
};

function showHide(s){
	var e=getElm(s);

	if(!e){
		return true;
	}

	if(active&&active!=e.id){
		var oE=getElm(active);
		if(document.all){
			oE.nextSibling.style.display=(window.opera)?"table-row":"block";
		} else {
			oE.nextSibling.nextSibling.style.display="table-row";
		}
		oE.style.display="none";
	}
	else if(!active&&find()){
		var i=subMenus.length;
		while(i-->0){
			if(e==getElm(subMenus[i][0])){
				if(document.all){
					_oE.nextSibling.style.display=(window.opera)?"table-row":"block";
				} else {
					_oE.nextSibling.nextSibling.style.display="table-row";
				}
				continue;
			} else {
				getElm(subMenus[i][0]).style.display="none";
			}
		}
	}

	if(e.style.display==""||e.style.display=="none"){
		if(document.all){
			e.style.display=(window.opera)?"table-row":"block";
			e.nextSibling.style.display="none";
		} else {
			e.style.display="table-row";
			e.nextSibling.nextSibling.style.display="none";
		}
	} else {
		if(document.all){
			e.nextSibling.style.display=(window.opera)?"table-row":"block";
		} else {
			e.nextSibling.nextSibling.style.display="table-row";
		}
		e.style.display="none";
	}

	active=e.id;

	return false;
};

function find(){
	if(subMenus.length<1||location.search.indexOf("cat=")<1||location.search.indexOf("cat=pics")>0){
		return 0;
	}

	var
		o=subMenus,
		i=o.length,
		l=location.search;
	while(i-->0){
		if(l.indexOf(o[i][1])>0){
			if(l.split(o[i][1])[1].indexOf(o[i][2])>0){
				_oE=getElm(o[i][0]);

				if(document.all){
					_oE.style.display=(window.opera)?"table-row":"block";
					_oE.nextSibling.style.display="none";
				} else {
					_oE.style.display="table-row";
					_oE.nextSibling.nextSibling.style.display="none";
				}
				continue;
			}
		}
		getElm(o[i][0]).style.display="none";
	}
	return 1;
};

window.onload=function(){
	find();
};

document.onclick=function(evnt){
    if(window.event){
        if(window.event.srcElement.tagName=="A")
            klicka(window.event.srcElement);
    } else if(evnt.target){
        if(evnt.target.tagName=="A")
            klicka(evnt.target);
    }
}
</script>
<base target="frameMain">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#669999" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"><br>
<br>
<br>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
&nbsp; <a href="#" target="_self" onclick="return showHide('sub1');">Meny 1</a>
&nbsp; <a href="#" target="_self" onclick="return showHide('sub2');">Meny 2</a>
&nbsp; <a href="#" target="_self" onclick="return showHide('sub3');">Meny 3</a>
	</td>
  </tr>

<tr id="sub1">
<td width="100%" height="10">

Underkategori 1 och allt annat som ska visas

    </td>
  </tr>

<tr id="sub2">
<td width="100%" height="10">

Underkategori 2 och allt annat som ska visas

   </td>
  </tr>

<tr id="sub3">
<td width="100%" height="10">

Underkategori 3 och allt annat som ska visas

    </td>
  </tr>

</table>
</body>
</html>
```

Permalänk: https://www.webforum.nu/p/100768

## #2 — Peter S, 2004-04-01T21:03Z

Detta menysystem är specialanpassat för medlemmen Asa ([tråden](http://www.webforum.nu/showthread.php?s=&forumid=24&threadid=73942&highlight=meny)) och är ingenting jag rekommenderar någon annan ;) 

Om du ända vill använda den föreslår jag att du bygger menyerna exakt som Asa har på sin [hemsida](//www.gruvsjo.com).

 :)

Permalänk: https://www.webforum.nu/p/1313160

---

Tråden på webben: https://www.webforum.nu/amne/javascript/100768-meny-fel
