Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu - hightlight when page viewed - mambo

Status
Not open for further replies.

tchaplin

Programmer
Jul 18, 2003
58
NZ
I am new to php and mambo which uses a file menu.php to populate the menu items from a mysql database it also sets css formatting for a menu - CODE BELOW

There is a 6th element which is the phone number this is formatted differently - hence the inclusion of class='phone-contact'


I am trying to get the menu item to remain highlighted if it is clicked on. For example if Projects is clicked - I would like Projects menu item to remain Highlighted - like the menu items do when the rollover occurs
Hopefully this makes sence

Thanks for your time - much appreciated Todd

<div id="menu-panel">
<ul>
<?php
$item_id = mysql_escape_string( $_GET['Itemid'] );
$qry = "SELECT id, name, link FROM #__menu WHERE menutype='mainmenu' and parent='0' AND access<='$gid' AND sublevel='0' AND published='1' ORDER BY ordering LIMIT 6";
$database->setQuery($qry);
$rows = $database->loadObjectList();
$counter = 1;
foreach($rows as $row) {
// echo "<li><a href='$row->link&Itemid=$row->id' ".( $row->id == $item_id ? "class='current'" : "" )." ><span>$row->name</span></a></li>";

if ( $counter == 6 ) {
// echo "<li class='phone-contact'><a href='$row->link&Itemid=$row->id' ".( $row->id == $item_id ? "class='current'" : "" )." ><span>$row->name</span></a></li>";
echo "<li class='phone-contact'>".( $row->id == $item_id ? "class='current'" : "" )."<span>$row->name</span></li>";


} else {
echo "<li><a href='$row->link&Itemid=$row->id' ".( $row->id == $item_id ? "class='current'" : "" )." ><span>$row->name</span></a></li>";
}

$counter += 1;
}
?>
</ul>
</div>
 
My Update

I think I can do it using on onclick='CngClass(this);' however there is something wrong with the syntax hmmmm what still banging my head [evil]
menu.php


echo "<li><a onclick='CngClass(this);' href='$row->link&Itemid=$row->id' ".( $row->id == $item_id ? "class='current'" : "" )." ><span>$row->name</span></a></li>";

Then I'm using the function called on the index.php page through <?php include'menu.php'; ?>

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
var Lst;

function CngClass(obj){
if (typeof(obj)=='string') obj=document.getElementById(obj);
if (Lst) Lst.className='';
obj.className='selected';
Lst=obj;
}

/*]]>*/
</script>

<style type="text/css">
.selected { font: bold 18px Arial, Helvetica, sans-serif; color:red; }

</style>

Any suggestions thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top