473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Javascript tree menu

I am trying to make a tree menu that is similar to this
http://genieindustries.com/service_manuals.asp where you can click an
list item and it will un-hide another list. It seems simple
enough...but when I try it here http://www.wcumc.org/wcumc/w/content.php?type=info
it works in reverse. Meaning, it starts with the list fully expanded
and then by clicking on the parent, it collapses.

So, how do I get it to start closed and then open when its clicked?

I am kinda weak in JS so this is probably a VERY simple question :-P

The relevant code I am working with goes like this -->
<script type="text/javascript" language="javascript">
function show( menu ) {
if( document.getElementById ) {
if( document.getElementById( menu ).style.display == 'block' ) {
document.getElementById( menu ).style.display = 'none';
} else {
document.getElementById( menu ).style.display = 'block';
}
} else if( document.all ) {
if( document.all[ menu ].style.display == 'block' ) {
document.all[ menu ].style.display = 'none';
} else {
document.all[ menu ].style.display = 'block';
}
}
}
</script>

and then to call it its just...

<ul>
<li><a href="javascript:show('menu11')">Test</a>
<ul id="menu11">

Apr 8 '07 #1
3 2350
On Apr 8, 12:15 pm, leja...@gmail.com wrote:
I am trying to make a tree menu that is similar to thishttp://genieindustries.com/service_manuals.aspwhere you can click an
list item and it will un-hide another list. It seems simple
enough...but when I try it herehttp://www.wcumc.org/wcumc/w/content.php?type=info
it works in reverse. Meaning, it starts with the list fully expanded
and then by clicking on the parent, it collapses.

<script>
function show(menu) {
var d=document,
elemS=(d.getElementById(menu)||d.all[menu]).style
elemS.display=elemS.display=='none'?'block':'none'
}

</script>

<button onclick="show('UL1')">Show/Hide</button>
<ul id="UL1" style="display:none">
<li>x</li>
<li>y</li>
<li>z</li>
</ul>

Apr 8 '07 #2
On Apr 9, 8:10 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On Apr 8, 12:15 pm, leja...@gmail.com wrote:
I am trying to make a tree menu that is similar to thishttp://genieindustries.com/service_manuals.aspwhereyou can click an
list item and it will un-hide another list. It seems simple
enough...but when I try it herehttp://www.wcumc.org/wcumc/w/content.php?type=info
it works in reverse. Meaning, it starts with the list fully expanded
and then by clicking on the parent, it collapses.

<script>
function show(menu) {
var d=document,
elemS=(d.getElementById(menu)||d.all[menu]).style
elemS.display=elemS.display=='none'?'block':'none'
A more generic display toggle is between '' and 'none'. An empty
string allows the display attribute to return to the default, or
whatever might have been set by CSS, not just block.
--
Rob

Apr 8 '07 #3
"RobG" <rg***@iinet.net.auwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
On Apr 9, 8:10 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
>On Apr 8, 12:15 pm, leja...@gmail.com wrote:
I am trying to make a tree menu that is similar to
thishttp://genieindustries.com/service_manuals.aspwhereyou can click an
list item and it will un-hide another list. It seems simple
enough...but when I try it herehttp://www.wcumc.org/wcumc/w/content.php?type=info
it works in reverse. Meaning, it starts with the list fully expanded
and then by clicking on the parent, it collapses.

<script>
function show(menu) {
var d=document,
elemS=(d.getElementById(menu)||d.all[menu]).style
elemS.display=elemS.display=='none'?'block':'none'

A more generic display toggle is between '' and 'none'. An empty
string allows the display attribute to return to the default, or
whatever might have been set by CSS, not just block.
I am glad I saw this again! I was wondering what it was I had read about that.

So, is this behavior fairly consistent? I had never heard of it before a week or so ago.
More often than not (hell, just recently) I used 'none', 'inline', or 'block' depending on
requirement. I never set it to '', because, well, I had no clue about it. : )

Thanks.

-Lost
Apr 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
2
by: pantagruel | last post by:
I have an old web application I did where browsers with dynamic capabilities received a drop down menu on the top of the page and a fold out on the left hand side of the page and non-dynamic...
1
by: lejason | last post by:
I am trying to make a tree menu that is similar to this http://genieindustries.com/service_manuals.asp where you can click an list item and it will un-hide another list. It seems simple...
7
by: sosamv | last post by:
Hi all!, I'm creating a app with PHP and MySQL, the system administrator is capable of creating profiles, on each profile we create, we add a custom access menu (a javascript tree view menu), theres...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.