Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: javascript

  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript

    I have a website with navigational links. They are javascript, some of them you will click and sub menus will drop. Below are my questions

    1) Is there a way that if you click one button with sub menus that you can click it again and it will minimize the sub menus

    2)With javascript a button that has javascript is there a way that you can click on the main menu button open a new page & open up the sub menus?

    3)With javascript can you have sub sub-menus like this...?
    Main Button
    Sub Menu 1
    Sub Menu 2
    Sub Sub-Menu 1

    Thanks for your help?

    Those links are at www.pctthinktank.org/wboy

    Thanks

    Michael Brown

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    The answer to all your questions is yes. The precise answers (ie some examples) are up the code you have. It is rather a personalized solution, not quite a general one.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The answer to #1 is:

    Code:
    <script type="text/javascript">
    <!--
    window.onload=show;
    function show(id) {
    	var d = document.getElementById(id);
    	var vis;
    
    	for (var i = 1; i<=10; i++) {
    		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
    	}
    
    	vis = d.style.display;
    
    	if (vis == 'block') {
    		d.style.display='none';}
    	else {
    		d.style.display='block';}
    	}
    //-->
    </script>
    I initially added a CLASS to the sub menus with a property of "display:none". But for the display/hide part to work you initially had to DOUBLE click the button ONE time. This set the DISPLAY as either none or block which passed the if stmnt. By going through you ORIGINAL code, this set the initial value which we could toggle.


    And as the poster above said, if you found this to be helpful, some rep points would be great!!!

    Have a good day!
    Radnor
    Last edited by radnor; 10-24-2006 at 07:19 PM.

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This code... If you click on memberships (with sub menu) will display it (subm). Then if you click it again it's closed then reopened. If however, you click a DIFFERENT submenu, the original closes and the new one will open.

    The way around this is on load, assign them a status (YOUR ORIGINAL FOR LOOP). Then make my code a simple toggle.

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But... This brings us a new problem.... If we open memberships then adult programs, BOTH stay open.

    Code:
    window.onload=noshow;
    function noshow() {
    
    	for (var i = 1; i<=10; i++) {
    		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
    	}
    }
    
    function show(id) {
    	var d = document.getElementById(id);
    	var vis;
    
    
    	vis = d.style.display;
    
    	if (vis == 'block') {
    		d.style.display='none';}
    	else {
    		d.style.display='block';}
    	}
    //-->

  • #6
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And the final script to make it all happen is:

    Code:
    window.onload=noshow;
    function noshow() {
    
    	for (var i = 1; i<=10; i++) {
    		if (document.getElementById('smenu'+i)) {
    			document.getElementById('smenu'+i).style.display='none';
    		}
    	}
    }
    
    function show(id) {
    	var d = document.getElementById(id);
    	var vis;
    
    	vis = d.style.display;
    
    	if (vis == 'block') {
    		d.style.display='none';
    	} else {
    		d.style.display='block';
    	}
    
    	for (var i = 1; i<=10; i++) {
    		if (id.substr(-1,1) != i) {
    			document.getElementById('smenu'+i).style.display='none';
    		}
    	}
    }

  • #7
    New Coder
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I am correct all this goes into the head? Dont worry you will get reconizitioj (sp) when used

    Thanks

    Mike

  • #8
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, your current script is JUST after the TITLE tag. Replace yours with mine.

    Now, NEVER take anyones word for it. Make a BACKUP copy FIRST! Test it make sure it is what you are looking for. I tested it in FF. I do not use IE, so I dont know about it.

    Radnor

  • #9
    New Coder
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay thanks for your help dude My friend gave me his copy of a menu maker. Umm so I have to check if they want this or the version my friend gave me. Either way it was very helpful and appriciative. This will show me how to use it in the future if they dont like it. lol.

    Thanks again

    Mike


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •