title: How to update a cookie value (and not change the expire date)? javascript
body: <p>I have next code where I do:</p>
  
  <p>Check if my cookie exist if it not exist then I create the cookie called value
  inside else  I read the cookie again and check if value is 1, here i would like to set a new value but not change the expire date and time of this cookie only update the value</p>
  
  <pre><code>if( readCookie("value")==null)
  {
  
  createCookie("value",1,1);
  }
  else
  {
  if(readCookie("value")==1)
  {
  /*here I would like to set to cookie called value the new value to 2 */
  }
  else
  {
  alert("no es uno");
  }
  }
  
  function createCookie(name, value, days) {
      var expires;
  
      if (days) {
          var date = new Date();
          date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
          expires = "; expires=" + date.toGMTString();
      } else {
          expires = "";
      }
      document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
  }
  
  function readCookie(name) {
      var nameEQ = encodeURIComponent(name) + "=";
      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, c.length);
          if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
      }
      return null;
  }
  
  function eraseCookie(name) {
      createCookie(name, "", -1);
  }
  </code></pre>