Hi
Third post regarding my menu, i have a menu that is included in all my pages.
When the my menu item is clicked it opens a new page and the clicked item changes his color to magenta this, is perfect.
Each Item has a submenu the problem starts when i open one of the submenu pages, the submenu disappear and i can see only the parent menu, this is wrong the submenu items should be visible and the clicked submenu item should be magenta:

the following is the left menu code:

<div id="logo">
<a href="index.php"><img src="images/logo.png" /></a>
</div>

<div id="left">
       <?php
    // include functions
    include_once('includes/functions.php');
    // array to hold left menu and submenu items
    $left_menu_items = array(
    'book.php' => array(
    'text' => 'Book Design',
    'submenu' => array('book1.php' => array('text' => 'book1'),
    'book2.php' => array('text' => 'book2'),
    'book3.php' => array('text' => 'book3'),
    'book4.php' => array('text' => 'book4')
    )
    ),
    'identityDesign.php' => array(
    'text' => 'Identity Design',
    'submenu' => array('ID_1.php' => array('text' => 'ID_1'),
    'ID_2.php' => array('text' => 'ID_2'),
    'ID_3.php' => array('text' => 'ID_3'),
    'ID_4.php' => array('text' => 'ID_4')   
    )
    ),
    'logos.php' => array(
    'text' => 'Logos'),
    'packaging.php' => array(
    'text' => 'Package Design',
    'submenu' => array('packaging.php#title' => array('text' => 'title'),
    'packaging.php#title1' => array('text' => 'title11'),
    'packaging.php#title2' => array('text' => 'title2'),
    'packaging.php#title3' => array('text' => 'title3'),
    'packaging.php#title4' => array('text' => 'title4')
    )
    ),
    'index.php' => array('text' => 'Selected Projects'),
    );
    // call the function that draws the menu
     echo '<div id="leftMenu">' . draw_menu($script_name, $left_menu_items) . '</div>',
     '<div class="hr"><hr /></div>';
     echo '<div id="submenu">' . draw_sub_menu($script_name, $left_menu_items) . '</div>';
    ?>
    </div>

And this is the "function.php" code:

    <?php
    // function to draw menu (top and left)
    function draw_menu($script, $items, $div_id) {
    // start the list for the menu
    $menu = ' <ul id="list-nav">';
    // loop through the array with menus and submenus
    foreach($items as $url => $val) {
    $text = $val['text'];
    if($script == $url) {
    // if the item in the array is the current page, highlight it
    $menu .= '<li><a style="color:#eb0089" href="#nogo"> '. $text . ' </a></li>';
    } else {
    // else display it as usual link
    $menu .= '<li><a href="' . $url . '">' . $text . '</a></li>';
    }
    }
    // end the list
    $menu .= '</ul>';
    return $menu;
    }
    // function to draw submenu below the main menu on left side
    function draw_sub_menu($script, $items) {
    // find the correct submenu items to draw
    foreach($items as $url => $val) {
    // if the current page is on the top level (index.php, book.php...)
    if($script == $url) {
    if(isset($val['submenu']) && !empty($val['submenu'])) {
    $submenu = draw_menu($script, $val['submenu']);
    return $submenu;
    } else {
    return '';
    }
    }
    // if the current page is not on the top level, examine each submenu entry
    if(isset($val['submenu']) && !empty($val['submenu'])) {
    if($script == $val['submenu']['url']) {
    $submenu = draw_menu($script, $val['submenu']);
    return $submenu;
    }
    }
    }
    // if no submenus were drawn return empty string
    return '';
    }
    ?>

Thanks in advance for your help

Member Avatar for LastMitch

Each Item has a submenu the problem starts when i open one of the submenu pages, the submenu disappear and i can see only the parent menu, this is wrong the submenu

I don't know why you didn't post all your code in one page instead of 3 separate code in 3 separate threads:

http://www.daniweb.com/web-development/threads/433122/menu-with-different-class

http://www.daniweb.com/web-development/threads/433120/-menu-with-a-name-that-works-only-in-chrome

You need javascript or ajax the data in the arrays.

Regarding about Chrome,

I assume you are using CSS3 not all CSS3 code works on all browsers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.