title: how to know if a user has a certain cookie using javascript
body: <p>I have been stuck on this problem for a couple hours now, and cant seem to get off of it. I have a html website where i'm giving a user a cookie called "schoolid" and it has the school's ID in it. If a user has a certain school ID, in this case "gms08",they will be redirected to another website. This is what i have so far in the cookie area.
  I have a check cookie function checking to make sure the user has it, but i cant seem to get it to pick up on the fact that the user has the cookie and it is gms08.</p>
  
  <p><a href="https://i.stack.imgur.com/wQjnx.png" rel="nofollow noreferrer">i.stack.imgur.com/wQjnx.png</a></p>
  
  <p>Pastebin: <a href="http://pastebin.com/Gfjc7iTG" rel="nofollow noreferrer">http://pastebin.com/Gfjc7iTG</a></p>
  
  <pre><code>&lt;script&gt;
  function setCookie(cname, cvalue, exdays) {
      var d = new Date();
      d.setTime(d.getTime() + (exdays*24*60*60*1000));
      var expires = "expires="+d.toUTCString();
      document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  }
  &lt;/script&gt;
  &lt;script&gt;
  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 "";
  }
  &lt;/script&gt;
  &lt;script&gt;
  function checkCookie() {
      var id = getCookie("schoolid");
      if (id != "") {
          alert("Welcome again ");
      } else {
      alert("user");
      }
  }
  &lt;/script&gt;
  </code></pre>