OK, here we go. The script is below the problem description and simply
represents a simplified version to illustrate the problem which I have not
been able to solve. I have spent ours on Google without tracking down the
issue.
It's menu script where I am using html/css dom to access the attributes. I
want to change the display attribute on child elements from 'none' to
'block' and the other way round when the parent node is clicked. That is
the basics but I want to refine that after this problem gets solved, if it
solvable.
The interesting and very annoying thing is that it works fine when applying
the 'block' attribute to the child nodes of the first parent 'a-1' which
shows and hides the child nodes fine. When I click the 'b-1' node that
works too BUT then the function exits and is called again from somewhere.
The alert('Exiting Function'); is there to show what's happening. The
function does terminate and then is called again as you will see.
I thought it might be the 'onclick' calls in the sibling elements but when I
take them out it still happens.
So, any hints as to what's going on are appreciated. This is definitely out
of my league.
Thanks, Walter
Start of SCRIPT:
---------------------------------------------------------->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">
<head>
<title>Menu Test</title>
<style type="text/css">
[id^='a'], [id^='b'],[id^='c'],[id^='d']{
width:150px;
border:0px;
text-align:left;
}
[id^='b'],[id^='c'],[id^='d']{
display:none;
}
[id^='a']{
background-color:yellow;
display:block;
}
[id^='b']{
background-color:lightblue;
text-indent:20px;
}
[id^='c']{
background-color:lightgreen;
text-indent:40px;
}
[id^='d']{
background-color:orange;
text-indent:60px;
display:block;
}
</style>
<script language="JavaScript">
var count = 0;
function findChildren(tmp){
//alert(count++);
var temp = "";
var status ="";
var mm = document.getElementById(tmp.id).childNodes;
var l = mm.length;
var tempId=mm[1].id;
for (i=0; i<l; i++){
if ((mm[i].nodeType == 1) && (mm[i].id == tempId)){
temp = mm[i].style.display;
switch (temp){
case '': mm[i].style.display =
'block';
break;
case 'none': mm[i].style.display =
'block';
break;
case 'block': mm[i].style.display =
'none';
break;
}
}
}
alert('Exiting Function');
}
</script>
</head>
<body>
This is a menu test!!
<br /><br />
<div id="Menu">Menu
<span id="a1" onclick="findChildren(this);">a-1 -->
<span id="b1" onclick="findChildren(this);">b-1 -->
<span id="c1">c-1</span>
<span id="c1">c-2</span>
<span id="c1">c-3</span>
</span>
<span id="b1">b-2</span>
<span id="b1">b-3</span>
</span>
<span id="a2" onclick="findChildren(this);">a-2 -->
<span id="b2" onclick="findChildren(this);">b-11
<span id="c2">c-1x</span>
<span id="c2">c-2x</span>
<span id="c2">c-3x</span>
</span>
<span id="b2">b-22</span>
<span id="b2">b-33</span>
</span>
<span id="a3" onclick="findChildren(this);">a-3 -->
<span id="b3" onclick="findChildren(this);">b-111
<span id="c3">c-1z</span>
<span id="c3">c-2z</span>
<span id="c3">c-3z</span>
</span>
<span id="b3">b-222</span>
<span id="b3">b-333</span>
</span>
</div>
<hr />
<span id='paste'></span>
</body>
</html>
---------------------------------------------------------->
End of SCRIPT:
-----Original Message-----
From: staffslug-bounces(a)staffslug.org.uk
[mailto:staffslug-bounces@staffslug.org.uk] On Behalf Of Tig
Sent: 18 February 2010 17:59
To: staffslug(a)staffslug.org.uk
Subject: Re: [Staffslug] Javascript Problem
Give it a go, the worst that could happen is that no one else knows :-)
On Thu, Feb 18, 2010 at 5:57 PM, walt <walt(a)helvatron.co.uk> wrote:
Hi,
Would it be ok to submit a javascript problem?. I simply cannot figure out
why a function exits and is called again from somewhere but I am stumped
as
to how it happens. I am not a programmer but I have done quite a bit
of
scripting.
I have tried in all major browser and the problem occurs in all of them.
I'll post the whole script, html - css and javascript with a description
of
the problem if one of you clever guys wouldn't mind have a quick
look.
Very many thanks, Walter
_______________________________________________
Staffslug mailing list
Staffslug(a)staffslug.org.uk
http://lists.staffslug.org.uk/mailman/listinfo/staffslug
_______________________________________________
Staffslug mailing list
Staffslug(a)staffslug.org.uk
http://lists.staffslug.org.uk/mailman/listinfo/staffslug