title: Javascript won't save cookie
body: <p>I'm using a quick Javascript code (based on a tutorial) to try and create an age screen on a site. However, although the age screen should only pop up once and then be fine for a while, it pops up every refresh. Here's the code I'm using:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function setCookie(cname, cvalue, exdays) {
      var d = new Date();
      d.setTime(d.getTime() + (exdays*24*60*60*1000));
      var expires = "expires="+d.toGMTString();
      document.cookie = cname + "=" + cvalue + "; " + expires;
  }
  function getCookie(cname) {
      var name = cname + "=";
      var ca = document.cookie.split(';');
      for(var i=0; i &lt; ca.length; i++) {
          var c = ca[i];
          while(c.charAt(0)==' ') c = c.substring(1);
          if(c.indexOf(name) == 0) return c.substring(name.length,c.length);
      }
      return "";
  }
  function checkCookie() {
      var age = getCookie("allowed");
      if (age != true) {
          age = confirm("you must be 18 or older to enter and view the content on this blog");
      }
      if (age == true) {
          setCookie("allowed", age, 7);
      } else if (age == false) {
          //window.location.replace("http://tumblr.com/dashboard");
      }
      return age;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I've checked every available online resource and tutorial I can find, but nothing explains why this won't save the cookie properly. If I open the console, it recognizes the site creating the cookie, but gives me undefined values for everything.</p>
  
  <p>If I have the console run the checkCookie() function, it returns the proper value depending on whether I clicked 'OK' or 'Cancel' but it still won't actually save that value into the cookie.</p>
  
  <p>Can <em>anyone</em> think of any reason this might be happening?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After changing the <code>age == true</code> checks from boolean checks into strings, it made no difference.</p>