title: Set cookie and display the value of cookie
body: <p>I am working on storing and reading information in Cookies. So basically I have two HTML pages with field of name. On page 1 I have to read the field and save the value into a cookie. And then submit, it will go to page 2, read the cookie and display the name that i typed on page 1. However, I could not display the value from page 1 on page 2. Here is my code:</p>
  
  <p>Page 1:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Save Value&lt;/title&gt;
      &lt;script type="text/javascript"&gt;
          function setCookie(cname, cvalue) {
              document.cookie = cname + "=" + cvalue + "; ";
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="display.html" method="get"&gt;
  &lt;label&gt; 
  First Name:
  &lt;input name="name" size="20" maxlength="25" type="text" id="name" /&gt;
  &lt;/label&gt;
  &lt;input type="submit" value="submit" onclick="setCookie()" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>Page 2:</p>
  
  <pre><code>    &lt;html&gt;
      &lt;head&gt;
      &lt;title&gt;Display&lt;/title&gt;
      &lt;script type="text/javascript"&gt;
      function readCookie(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;/head&gt;
  
      &lt;body&gt;
      &lt;form action="#"&gt;
      &lt;label&gt;
      First Name:
      &lt;input name="namefield" size="20" maxlength="25" type="text" id="name" readonly="readonly" /&gt;
      &lt;/label&gt;
      &lt;script type="text/javascript"&gt;
      var val1 = document.getElementById("name").value;
      val1 = readCookie('namefield');
      &lt;/script&gt;
      &lt;/form&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>Any idea about this problem? Thank you so much!</p>