why aren't the cookies saved ?
<p>why aren't the cookies saved when i run the following script:</p>

<pre><code>window.onload=init;

function init() {
var userName="";
if(document.cookie != "") {
    username=document.cookie.split("=")[1];
}

document.getElementById("name_field").value = username;
document.getElementById("name_field").onblur = setCookie;
}

function setCookie() {
var exprDate = new Date();
exprDate.setMonth(exprDate.getMonth() + 6);

var userName = document.getElementById("name_field").value;
document.cookie = "username=" + username + ";path=/;expires=" + exprDate.toGMTString();
}
</code></pre>

<p>When i refresh the page the <code>text-field</code> gets empty? why is so ?
<strong>HTML</strong></p>

<pre><code>&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script type="text/javascript" src="writing_cookie.js"&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form&gt;
&lt;label&gt;Enter your name&amp;nbsp;&amp;nbsp;&lt;input type="text" id="name_field" /&gt;&lt;/label&gt; &lt;br/&gt;
&lt;input type="submit" value="submit" /&gt;
&lt;/form&gt;
&lt;/body&gt; 
&lt;/html&gt;
</code></pre>
