title: Keep option after a refresh in HTML using Javascript
body: <p>I'm trying to keep the selected option in HTML after doing a refresh using local storage. I followed the example mentioned <a href="https://stackoverflow.com/questions/22192640/keep-option-selected-after-a-refresh">here</a>
  Below is my code.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>document.getElementById("interface-output").onchange = function() {
    localStorage.setItem('selectedtem', document.getElementById("interface-output").value);
  };
  
  if (localStorage.getItem('item')) {
    document.getElementById("selectedtem").options[localStorage.getItem('selectedtem')].selected = true;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="row" id="ott-redirect-interface-selector"&gt;
    &lt;label&gt;Output Interface&lt;/label&gt;&lt;br&gt;
    &lt;select id="interface-output" class="browser-default"&gt;
      &lt;option value="select"&gt;Select an interface&lt;/option&gt;
      &lt;option value="eth0"&gt;eth0&lt;/option&gt;
      &lt;option value="eth1"&gt;eth1&lt;/option&gt;
    &lt;/select&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Unfortunately this setting doesn't preserve the selected option after a refresh. Any suggestions please ?</p>