So, I have a jquery menu using UL and LI's. I wanted a page state so as to display to the user which page he's in by keeping a hover state on the menu item.
I've created a javascript file to function and read data when the user clicks a link. This function sets a cookie with the text data retrieved from the li
function setCookie(name, value, days) {
var expireDate = new Date()
var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}
function enact(what){
var value = $(what).text()
setCookie("selected", value, 60)
}
function enactHome(){
setCookie("selected", "Home", 60)
}
function enactLog(){
setCookie("selected", "Log", 60)
}
Then I have the following (read the cookie and if it's the same as the text, set the style):
<ul id="nav">
<li önclick="enactHome();" <?php if($_COOKIE["selected"] == "Home"){ echo "class='navselected'"; }?> ><a önclick="enactHome();" href="index1.php">Home</a></li>
<li önclick="enact(this);" <?php if($_COOKIE["selected"] == "Student"){ echo "class='navselected'"; }?>><a href="#">Student</a>
<ul>
<li önclick="enact(this);"><a href="add_student.php">Add Student</a></li>
<li önclick="enact(this);"><a href="edit_student.php">Edit/Delete Student</a></li>
</ul>
</li>
<li önclick="enactLog();" <?php if($_COOKIE["selected"] == "User Log"){ echo "class='navselected'"; }?>><a önclick="enactLog();" href="log.php">User Log</a></li>
Now the problem is that the Student Link works and sets the menu state with a background in css as it should, but the others don't. I have tried to use the enact(this) on the Home and Log, but with no success. What am I doing wrong? Please help ;/
Thanks,
Francesco