title: Set cookie value from variable
body: <p>I have been recently trying to set a cookie holding the user's name, it opens a prompt pop-up box asking for a new user name. When the user inserts the user name and clicks "ok" it doesn't treat the variable (sconName) as a variable and just puts "sconName".</p>
  
  <p>Note: Scon is the name of the website.</p>
  
  <p>Heres the only script I am using:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
  &lt;script&gt;
  function readCookie(name) { 
      var nameEQ = 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 c.substring(nameEQ.length,c.length); 
      } 
      return null; }
      &lt;/script&gt;
  &lt;script&gt;
    var username = readCookie('sconName');
  if (username) {
     document.write("Your current username is: " + username);
  }
    else {
      document.write("You have no user name");
    }
  
    function changeUsername() {
      var changedName=prompt("Enter user name.");
      if (changedName) {
  document.cookie = 'sconName=changedName; expires=Wed, 1 Jan 2070 13:47:11 UTC; path=/'}}
    &lt;/script&gt;
  &lt;button onclick="changeUsername()"&gt;Change&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Please can you explain how to tell the system that its a variable not just text.
  Thanks.</p>