title: How to set cookie's expire date with js?
body: <p>This is my script. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script&gt;
          function save() {
              var x=document.getElementById("user").value;
              var y=document.getElementById("password").value;
              document.cookie=x+" "+y;
          }
          function write() {
              document.write(document.cookie);
          }
  &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This works fine, it remembers the value of var x and y and writes them when function write() is called. When I close the browser the cookie gets deleted, as it should. But I would like to set an expire date of one year; I tried in many ways but I really can't get it to work. Any help?</p>