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 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2002
    Location
    Israel
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disappearing submenu

    Hi
    I have a menu that is included in all my pages.
    When the 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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    How many of these threads are you going to make?
    Does the data in your source show appropriately for what you have in your PHP code? If it does, this isn't a PHP issue, its an HTML/CSS issue. Since this code isn't placed in [php][/php] tags, I won't go through it to verify, but your HTML appears to be built properly. Therefore the problem is with your CSS.

  • #3
    New Coder
    Join Date
    Nov 2002
    Location
    Israel
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is not an html issue, i'm missing something in the php code that says : when one of the submenu item is clicked all the submenu items should be visible and the clicked item should change his color
    Thanks

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Does the source show all of the iterations properly or no?

  • #5
    New Coder
    Join Date
    Nov 2002
    Location
    Israel
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, i have also a top menu.php but i don't think that it changes something:

    <div id="menu" >
    <?php
    // include functions
    include_once('includes/functions.php');
    // array to hold top menu
    $top_menu_items = array(
    'index.php' => array('text' => 'Home'),
    'about.php' => array('text' => 'About'),
    'contact.php' => array('text' => 'Contact')
    );
    // call the function that draws the menu
    echo draw_menu($script_name, $top_menu_items);
    ?>
    </div>

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If all the data is there and nested as appropriately within your HTML, then this is not a PHP issue.
    PHP is not capable of responding to client events such as onclick. That is javascript.


  •  

    Posting Permissions

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