Need help with dynamicdrive accordion menu script

Discussion in 'JavaScript' started by ziplock122949, Feb 28, 2011.

  1. #1
    I am trying to install a accordion side menu onto a page and am having some issues. Not knowing javascript isn't helping. The script and setup is from http://dynamicdrive.com/dynamicindex17/ddaccordionmenu-glossy.htm. The page that I am testing the dropdown on is engineeringtshirts.com

    I am having issues in 2 parts. First, I want the previous state of the pull downs to be reset on page refresh. Right now if you have the 3rd pull down open and refresh, the third pull down will still be open even though the default is set to the second pull down.

    The second part that I am having trouble with is setting the defaultexpanded page by page. I want/have the main function and menu layout being pulled from additional php files (so I can update the menu and links in one file instead of 40 files later). I have found a way to declare a php variable as a value on an individual page then inject the php variable into the defaultexpanded section (shown below). I am wondering how to do the same thing in javascript.

    <?php 
    $currentexpand=2; 
    ?>
    
    then in the javascript ddaccordion.init
    
    defaultexpanded: [<?php echo $currentexpand ?>],
    
    Code (markup):
     
    ziplock122949, Feb 28, 2011 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    It is set through a cookie.
    I think they provide a way to handle this behavior:
    Try setting
    persiststate: false,
    PHP:
    instead of true ?
     
    hdewantara, Mar 1, 2011 IP
  3. ziplock122949

    ziplock122949 Active Member

    Messages:
    159
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Yeah, just saw that. I dont know how I missed that earlier.
    How do I declare and set a variable then have it in the defaultexpanded: [variable],
     
    ziplock122949, Mar 1, 2011 IP
  4. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #4
    Hi ziplock122949,
    I think it is possible to just put a js var there.

    And controlling the var is possible e.g through URL GET (assuming the filename as
    current.htm):
    http://engineeringtshirts.com/current.htm?[COLOR="red"]def_exp[/COLOR]=x
    Code (markup):
    where x is defaultexpanded number, passed into that URL.

    To have this, add a piece of code on top:
    <script type="text/javascript">
    if (location.search.length > 0){
    	var 
    		get_params = location.search.substr(1).split("=");
    	if ((get_params.length === 2) && (get_params[0] === "[COLOR="red"]def_exp[/COLOR]" ))
    		[COLOR="red"]def_exp[/COLOR] = get_params[1];
    	else
    		[COLOR="red"]def_exp[/COLOR] = "";
    }
    else{
    	[COLOR="red"]def_exp[/COLOR] = "";
    }	
    
    ddaccordion.init({
    	headerclass: "submenuheader",
    	...
    	defaultexpanded: [[COLOR="red"]def_exp[/COLOR]],
    	...
    Code (markup):
     
    hdewantara, Mar 1, 2011 IP
  5. ziplock122949

    ziplock122949 Active Member

    Messages:
    159
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Well i'm stupid. I was not looking for the url part, but i your response did help me recognize something that I passed over, I was not setting the variable BEFORE the ddaccordion.init. Thanks for the help.
     
    ziplock122949, Mar 1, 2011 IP
  6. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #6
    My pleasure...
    And get some sleep before you miss more :D
     
    hdewantara, Mar 1, 2011 IP