title: Trying to store range slider value in a cookie
body: <p>I have html range sliders on a page, and I want to store the value to a cookie when a user moves the slider, so that the slider will automatically be set to what they selected when they come back again.</p>
  
  <p>I am very new to javascript (know the bare basics). So I followed this tutorial: <a href="https://www.youtube.com/watch?v=VqzSex_2tDc" rel="nofollow">https://www.youtube.com/watch?v=VqzSex_2tDc</a></p>
  
  <p>Firstly... in that tutorial the guy added "onchange="setMyCookie()" to an html dropdown box. So that the dropdown would automatically show the cookie value. However, I am not using a dropdown, I'm using an html range slider. So can I add "onchange="setMyCookie()" directly to a range slider? Like so, see below - Is that wrong? </p>
  
  <pre><code>&lt;input type="range" id="loan" name="loan" min="5000" max="500000" step="5000" onchange="setLoanCookie()"&gt;
  </code></pre>
  
  <p>I noticed other tutorials ads it to a submit button. Can I store values of range sliders to a cookie without requiring the user to click submit first?</p>
  
  <p>After following the tutorial... this is what I have.... is this close to right? Or am I far off... what am I doing wrong because it's not working?</p>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  window.onload = function ()
  {
      if (document.cookie.length != 0)
      {
          var nameValueArray = document.cookie.split("=");
          document.getElementById("loan").value = nameValueArray[1];
      }
  }
  
  function setLoanCookie()
  {
      var selectedLoan = document.getElementById("loan").value;
      document.cookie = "mloan=" + selectedLoan +
                          ";expires=Fri, 5 Dec 2016 01:00:00 UTC;";
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="range" id="loan" name="loan" min="5000" max="500000" step="5000" onchange="setLoanCookie()"&gt;
  </code></pre>