title: Verify if Cookie exists and storing the information
body: <p>I'm new to Javascript/Ajax and I'm trying to store a user's name using cookies. I have a form and would like to remember the person's first name (id = firstName). If they already filled it out in the past I want to display his/her name in a span element the next time they visit the page.</p>
  
  <p>This is what I would like to do using pseudo code. I hope it's clear....</p>
  
  <p>If cookie (called name) exists, display that information in the tag element "span"</p>
  
  <p>else</p>
  
  <p>Store that cookie when  the user fills out the form</p>
  
  <p>(I have an input with type="submit" as my button if that matters)</p>
  
  <hr>
  
  <p>@banana right now I modified my code to match all the tag names and ids i have. However nothing displays in the span if I type in a name in the form, submit and come back after on the page.</p>
  
  <pre><code>function setCookie(cname, cvalue, milliseconds) {
      var d = new Date();
      d.setTime(d.getTime() + (milliseconds));
      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].trim();
          if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
      }
      return "";
  }
  
  document.onload = checkIfCookieExists;
  function checkIfCookieExists(){
  var firstNameFromCookie = getCookie('firstName');
  if(firstNameFromCookie == ''){
     // cookie wasnt set
  
  }
  else{
     // cookie was set
     var display = document.getElementsByTagName('span');
     display.innerHTML = firstNameFromCookie;
  }
  }
  
  function init(){
   var firstName = document.getElementById('firstName');
   var cookieExpieryTimeInMilliseconds = 1000 * 60 * 60; //1000 milliseconds * 60 seconds * 60 minutes - results in 1 hour time.
   setCookie('firstName',firstName ,cookieExpieryTimeInMilliseconds );
  }
  
  window.onload = init();
  </code></pre>