title: JavaScript - Save checkbox state shared between documents using sessionStorage
body: <p>I'm trying to save the state of a checkbox using sessionStorage. I'm quite new to JavaScript so my understanding is pretty basic.</p>
  
  <p>I'm using a checkbox on a website to display the navigation menu. This checkbox is present on each page of the website (same id). The aim of saving the checkbox state is to have the navigation menu already "open" when a new page is navigated to. Currently the menu "jumps" closed upon page changes and defeats the purpose of the CSS transition effect.</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Thanks</p>
  
  <p>This is what I've got so far (content butchered from around the web).</p>
  
  <p>JS:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function checkFunction(){
      var checkbox = document.getElementById("nav-btn");
      checkbox.addEventListener("onChange",OnChange,false);
  }
  function save(){
      var nav-btn=document.getElementById("nav-btn").value;
      sessionStorage.setItem(nav-btn);
  }
  window.addEventListener("load",checkFunction,false);
  &lt;/script&gt;
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="checkbox" id="nav-btn" class="nav-btn" /&gt;
  &lt;label for="nav-btn"&gt;&lt;/label&gt;
  </code></pre>