![]() |
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 |
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. |
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 |
Does the source show all of the iterations properly or no?
|
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> |
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. |
| All times are GMT +1. The time now is 01:24 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.