title: Retrieving multiple string values from localstorage in javascript
body: <p>I am attempting to pull a string of data from localstorage in javascript and combine multiple values from multiple strings. For example
  I may have the following 2 strings</p>
  
  <pre><code>Bob;companyA;6141692120;email1@email.com;1 John St;;Bellevue;6056;;6;10;20.00;52.800000000000004;72.80;7.28;80.08;
  Jane;companyB;6157692120;email2@email.com;1 Jack St;;Bellevue;6056;;6;10;20.00;52.800000000000004;72.80;7.28;80.08;
  </code></pre>
  
  <p>I want to ignore the first few and add the last 5 or 6 together from each, so value [13] in string A + value [13] in string B = X, there will be doens of strings and they all have random numbers, I have attached the javascript code below and am hoping someone can point me in the right direction.</p>
  
  <pre><code>windows.onload= getAllItems();
  function getAllItems(){
  
  var all = [];
  for(var i = 0, j = localStorage.length; i &lt; j; i++) {
      all[i] = localStorage[i].split(';');
  }
  
  var sum = 0;
  for(var i = 0, j = all.length; i &lt; j; i++) {
      sum += all[i][12];
  }
  
  var bags = all[9];
  var distance = all[10];
  var hdelivery_fee = all[11];
  var hprice = all[12];
  var htotal_notax = all[13];
  var hgst = all[14];
  var htotal_tax = all[15];
  var hordernumber  = all[16];
  
  document.write('Number of Bags; ' + bags + '&lt;br /&gt;');
  document.write('Distance; ' + distance + '&lt;br /&gt;');
  document.write('Delivery Fee; $' + hdelivery_fee + '&lt;br /&gt;');
  document.write('Price of Bags; $' + hprice + '&lt;br /&gt;');
  document.write('Total Ex-GST; $' + htotal_notax + '&lt;br /&gt;');
  document.write('GST; $' + hgst + '&lt;br /&gt;');
  document.write('Total Inc GST; $' + htotal_tax + '&lt;br /&gt;');
  document.write('hordernumber; ' + hordernumber + '&lt;br /&gt;');
  }
  </code></pre>
  
  <p>Also it is probably worth mentioning that this is an assignment and as such I am not allowed to use JSON or jquery in any capacity</p>
  
  <p>EDIT: I have changed the code to match the answer given below, and I think i have taken the output out of the loop, however I am incredibly new at this so a lot of it is hit and miss. It doesnt seem to be working as is even though it looks like it should (to me)</p>
  
  <p>EDIT2: Adding javascript for localstorage info source</p>
  
  <pre><code>function source()
  {
  var newDate = new Date();
  var itemId = newDate.getTime();
  var values = new Array();
      var name = document.getElementById("name").value;
      var company = document.getElementById("company").value;
      var contactnumber= document.getElementById("contactnumber").value;
      var email = document.getElementById("email").value;
      var address1 = document.getElementById("address1").value;
      var address2 = document.getElementById("address2").value;
      var suburb = document.getElementById("suburb").value;
      var postcode = document.getElementById("postcode").value;
      var comments = document.getElementById("comments").value;
      var bags = document.getElementById("bags").value;
      var distance = document.getElementById("distance").value;
      var hdelivery_fee = document.getElementById("hdelivery_fee").value;
      var hprice = document.getElementById("hprice").value;
      var htotal_notax = document.getElementById("htotal_notax").value;
      var hgst = document.getElementById("hgst").value;
      var htotal_tax= document.getElementById("htotal_tax").value;
      var hordernumber= document.getElementById("hordernumber").value;
  
  
  values.push(name);
  values.push(company);
  values.push(contactnumber);
  values.push(email);
  values.push(address1);
  values.push(address2);
  values.push(suburb);
  values.push(postcode);
  values.push(comments);
  values.push(bags);
  values.push(distance);
  values.push(hdelivery_fee);
  values.push(hprice);
  values.push(htotal_notax);
  values.push(hgst);
  values.push(htotal_tax);
  values.push(hordernumber);
  
  try {
      localStorage.setItem(itemId, values.join(";")); 
  } catch (e) {
      if (e == QUOTA_EXCEEDED_ERR) {
          alert("Quota exceeded!");
      }
  }
  
  }
  </code></pre>
  
  <p>EDIT3:</p>
  
  <p>adding entire html page for location of report including javascript.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Form Processor&lt;/title&gt;
       &lt;link rel="stylesheet" type="text/css" href="layout.css"&gt;
  
  
  
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="header"&gt;
          &lt;h1 id="main_tile"&gt; Everwarm Fuel Merchants - Daily Report &lt;/h1&gt;
  
      &lt;/div&gt;
  &lt;h1&gt; Daily Sales Summary &lt;h1&gt;
  
  &lt;p&gt;
  &lt;script&gt;
  function getAllItems(){
      var all=[];
      for (i = 0,j=localStorage.length; i&lt;j; i++) {
          all[i] = localStorage.getItem(localStorage.key(i)).split(';');
      }
      function getTotal(index) {
           var sum = 0;
           for(var i = 0, j = all.length; i &lt; j; i++) {
              sum += parseFloat(all[i][index]);
          }
          return sum;
      }
      var bags = getTotal(9);
      var distance = getTotal(10);
      var hdelivery_fee = getTotal(11);
      var hprice = getTotal(12);
      var htotal_notax = getTotal(13);
      var hgst = getTotal(14);
      var htotal_tax = getTotal(15);
      var hordernumber = getTotal(16);
  
      document.write('Number of Bags; ' + bags + '&lt;br /&gt;');
      document.write('Distance; ' + distance + '&lt;br /&gt;');
      document.write('Delivery Fee; $' + hdelivery_fee + '&lt;br /&gt;');
      document.write('Price of Bags; $' + hprice + '&lt;br /&gt;');
      document.write('Total Ex-GST; $' + htotal_notax + '&lt;br /&gt;');
      document.write('GST; $' + hgst + '&lt;br /&gt;');
      document.write('Total Inc GST; $' + htotal_tax + '&lt;br /&gt;');
      document.write('hordernumber; ' + hordernumber + '&lt;br /&gt;');
    }&lt;/script&gt;
  
    &lt;/p&gt;
  
  
  &lt;input type="button" value="Clear storage" onclick="localstorage.clear()" &gt; &lt;/input&gt;
  
  &lt;input type="button" value="Return" onclick="history.back()"&gt; &lt;/input&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>