Jump to content


Photo

Newbie's Creating Menu with Javascript Tree neeeedsss Help


  • Please log in to reply
1 reply to this topic

#1 Qazsad

Qazsad
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 07 June 2006 - 09:17 AM

Hello Guys
Do you have sample codes for creating javascript Tree. Coz i would like to create a menu on my page
and hiding its submenu first. The Submenu's will only be shown if The Mainmenu will be clicked and other submenus from other will be hidden if they are not part of the current mainmenu.
Say

Selecting MainMenu2:

MainMenu1
MainMenu2
MM2_SubMenu1
MM2_SubMenu2
MainMenu3

Selecting MainMenu1:

MainMenu1
MM1_SubMenu1
MM1_SubMenu2
MainMenu2
MainMenu3




#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 07 June 2006 - 07:12 PM

try this
<script language="javascript">
function hide(){
     var sub_menus_array = new Array("sub1","sub2","sub3");  // sub menu ids
     for(i=0; i<sub_menus_array.length; i++){
          document.getElementById(sub_menus_array[i]).style.display = "none";
     }
}
function show(sub_menu){
     hide();
     document.getElementById(sub_menus_array[i]).style.display = "block";
}
<script>

<a href="#" onClick="show('sub1');">MainMenu1</a>
<div id="sub1" style="display:none;">
MM1_SubMenu1
MM1_SubMenu2
</div>
<a href="#" onClick="show('sub2');">MainMenu2</a>
<div id="sub2" style="display:none;">
MM2_SubMenu1
MM2_SubMenu2
</div>
<a href="#" onClick="show('sub3');">MainMenu3</a>
<div id="sub3" style="display:none;">
MM3_SubMenu1
MM3_SubMenu2
</div>

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users