title: Can't set a sessionStorage to a variable in Javascript
body: <p>I have an extremely long list of file path names and links for a flash gallery. This array is interacted with a back, random and next button. I am trying to set the variable 'c' to a sessionStorage variable so when the page refreshs (Which I require it to do for reasons) the value is saved. I have tested these variables out without the sessionStorage and everything works dandy. One thing to note though is that the "Random" button works while the back and next buttons do not work.</p>
  
  <p>I attempted to convert all three but I only showed what I changed with the 'back' function so everyone could get a perspective on what worked before this.</p>
  
  <pre><code>var c;
      sessionStorage.setItem('order', c);
      var flashcon, test, temp;
      var backbutt, randbutt, nextbutt;
  
      backbutt = document.getElementById('back');
      randbutt = document.getElementById('rand');
      nextbutt = document.getElementById('next');
      flashcon = document.getElementById('flashcon');
  
      function init() {
          if (sessionStorage.getItem('ref') == 1) {
              console.log('Value: ref==1(back)');
              back();
          } else if (sessionStorage.getItem('ref') == 2) {
              console.log('Value: ref==2(rand)');
              rand();
          } else if (sessionStorage.getItem('ref') == 3) {
              console.log('Value: ref==3(next)');
              next();
          } else {
              console.log('State: First session or refresh session');
          }
  
          // Scripts for the buttons
  
          backbutt.onclick = function () {
              console.log('Event: backbutton.onclick');
              sessionStorage.setItem('ref', 1);
              location.reload();
          };
  
          randbutt.onclick = function () {
              console.log('Event: randbutton.onclick');
              sessionStorage.setItem('ref', 2);
              location.reload();
          };
  
          nextbutt.onclick = function () {
              console.log('Event: nextbutton.onclick');
              sessionStorage.setItem('ref', 3);
              location.reload();
          };
      }
  
      // Changes the name at the top of the screen
      function displayFiles() {
          console.log('Called: displayFiles()');
          test = paths[c].substring(paths[c].lastIndexOf('.') + 1, paths[c].length);
          document.getElementById('title').innerHTML = displaytext[c];
  
          flashcon.innerHTML =
              '&lt;object id="flashcontent" data="' + paths[c] + '"&gt;' +
              '&lt;param name="movie" type="application/x-shockwave-flash"&gt;' +
              '&lt;/object&gt;';
      }
  
      // What switches the flashs
      function back() {
          console.log('Called: back()');
          sessionStorage.removeItem('ref');
  
          if (sessionStorage.getItem('order') == 0) {
              console.log('Did the whole if thing');
              c = paths.length;
              c = sessionStorage.getItem('order');
          }
          console.log('Went past the if');
          c--;
          c = sessionStorage.getItem('order');
          displayFiles();
          download();
          console.log('Value of "c": ' + c);
      }
  
      function next() {
          console.log('Called: next()');
          sessionStorage.removeItem('ref');
  
          if (c == paths.length - 1) {
              c = -1;
          }
  
          c++;
          displayFiles();
          download();
          console.log('Value of "c": ' + c);
      }
  
      function rand() {
          console.log('Called: rand()');
          sessionStorage.removeItem('ref');
  
          temp = c;
          while (c == temp) {
              c = Math.floor(Math.random() * paths.length);
          }
          displayFiles();
          download();
          console.log('Value of "c": ' + c);
      }
  </code></pre>
  
  <p>(Little explanation of my code so it makes sense)</p>
  
  <p>When the user comes into the page for the first time it will go to the init function which will go to the "else" statement this statement does nothing and waits for the user to click on a button which assigns a variable which refreshs the page. After the page is refreshed it will run the init again which will use one of the "if" statments since a variable has been set. These if statements call the scripts to change what is contained inside the flash window.</p>