title: JS Save cookie on form submit
body: <p>I'm trying to create a simple form that pops up (i'll be putting the below code into a bootstrap modal) and asks a user to select their location from a drop down list.</p>
  <p>I think I'm almost there with this code however the cookie value is always stored as &quot;undefined&quot; when i click submit.</p>
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script&gt;
  function setCookie(cookieName, cookieValue, nDays) {
      var today = new Date();
      var expire = new Date();
  
      if (!nDays) 
          nDays=1;
  
      expire.setTime(today.getTime() + 3600000*24*nDays);
      document.cookie = cookieName+&quot;=&quot;+escape(cookieValue) + &quot;;expires=&quot;+expire.toGMTString();
  }
  
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form onsubmit=&quot;setCookie('location', this.value, 365);&quot;&gt;
      &lt;select&gt;
          &lt;option value=&quot;location1&quot;&gt;Location 1&lt;/option&gt;
          &lt;option value=&quot;location2&quot;&gt;Location 2&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;
  &lt;/form&gt;
  &lt;/body&gt;   
  &lt;/html&gt;
  </code></pre>
  <p>Any advice on how I can get it to store the cookie value from the dropdown?</p>