javascript define cookie
<p>Something very wrong is going on this piece of code:</p>

<pre><code>function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i&lt;ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("username");
if (username=="username"){
    document.getElementById(mydivx).style.display = 'block';  }else{
    document.getElementById(mydivx).style.display = 'none'; 
  }
}
</code></pre>

<p>and a button to define the cookie:</p>

<pre><code>&lt;a href="#" onClick="setCookie("username",username,365); return true"&gt;esconder&lt;/a&gt;
</code></pre>

<p>So this should be happening, if the button is clicked, it defines a cookie named "username" with the value "username", the getcookie function gets the cookie username and its value.</p>

<p>What am i doing wrong?</p>

<p>Hope you can help me guys ! </p>

<p>EDIT: SOLUTION:</p>

<p>Just remove the ";" from the call, and add some single quotations to the code from the button:</p>

<p>esconder</p>

<p>Thanks to stealthyninja</p>
