Click here to Skip to main content
16,008,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
function setCookie(name, value, days) {
            var expireDate = new Date()
            //set "expstring" to either future or past date, to set or delete cookie, respectively
            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):

PHP
<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
Posted
Updated 17-Feb-12 6:53am
v2

1 solution

anyone??? Why is it not saving it to the session? Could anyone help please?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900