Menu Page State
<p>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.</p>

<p>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</p>

<pre><code>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(&amp;quot;selected&amp;quot;, value, 60)
        }

        function enactHome(){
             setCookie(&amp;quot;selected&amp;quot;, "Home", 60)
        }

        function enactLog(){
             setCookie(&amp;quot;selected&amp;quot;, "Log", 60)
        }&lt;/pre&gt;
</code></pre>

<p>Then I have the following (read the cookie and if it's the same as the text, set the style):</p>

<pre><code>&lt;ul id="nav"&gt;
    &lt;li onclick="enact(this);" &lt;?php if($_COOKIE["selected"] == "Home"){ echo "class='navselected'"; }?&gt; &gt;&lt;a href="index1.php"&gt;Home&lt;/a&gt;&lt;/li&gt;

&lt;li onclick="enact(this);" &lt;?php if($_COOKIE["selected"] == "Student"){ echo "class='navselected'"; }?&gt;&gt;&lt;a href="#"&gt;Student&lt;/a&gt;
                        &lt;ul&gt;
                            &lt;li onclick="enact(this);"&gt;&lt;a href="add_student.php"&gt;Add Student&lt;/a&gt;&lt;/li&gt;
                            &lt;li onclick="enact(this);"&gt;&lt;a href="edit_student.php"&gt;Edit/Delete Student&lt;/a&gt;&lt;/li&gt;                              
                        &lt;/ul&gt;
                    &lt;/li&gt;

&lt;li onclick="enact(this);" &lt;?php if($_COOKIE["selected"] == "User Log"){ echo "class='navselected'"; }?&gt;&gt;&lt;a href="log.php"&gt;User Log&lt;/a&gt;&lt;/li&gt;    
&lt;/ul&gt;                       
</code></pre>

<p>Now the problem is that the Student Link works upon loading the page and sets the menu state with a background in css as it should. The others do set the css, but the page has to be refreshed again. So if I click Home, the page loads with the student selected. When the page is refrehed, it loads the home selected.</p>

<p>I have tried to use the enactHome() and encatLog() on the Home and Log, but with no success. What am I doing wrong? Please help ;/</p>

<p>Thanks,
Francesco</p>
