local storage - retrieving last key in javascript localstorage -


i doing uni assignment please excuse coplete lack of knowledge here. have been tasked creating web based app "client" requires me open invoice after have completed details, far have form working fine, can save localstorage without issue , can retrieve information in format want.

the issue if have multiple "orders' can retrieve first string saved localstorage , cannot figure out how make display newest/last one.

the key randomly generated number derived date had assume large quantity of orders. have attached code below if can appreciate it. cannot use jquery or json or that. have been told not able use these. cannot use server (php etc).

thanks steve

<script> var = 0;  var itemkey = localstorage.key(i); var values = localstorage.getitem(itemkey); values = values.split(";"); var name = values[0]; var company = values[1]; var contactnumber = values[2]; var email = values[3]; var address1 = values[4]; var address2 = values[5]; var suburb = values[6] var postcode = values[7]; var comments = values[8]; var bags = values[9]; var distance = values[10]; var hdelivery_fee = values[11]; var hprice = values[12]; var htotal_notax = values[13]; var hgst = values[14]; var htotal_tax = values[15]; var hordernumber  = values[16];   document.write('name: ' + name + '<br />'); document.write('company: ' + company + '<br />'); document.write('contact: ' + contactnumber + '<br />'); document.write('email; ' + email + '<br />'); document.write('address; ' + address1 + '<br />'); document.write('address; ' + address2 + '<br />'); document.write('suburb; ' + suburb + '<br />'); document.write('postcode; ' + postcode + '<br />'); document.write('comments; ' + comments + '<br />'); document.write('number of bags; ' + bags + '<br />'); document.write('distance; ' + distance + '<br />'); document.write('delivery fee; $' + hdelivery_fee + '<br />'); document.write('price of bags; $' + hprice + '<br />'); document.write('total ex-gst; $' + htotal_notax + '<br />'); document.write('gst; $' + hgst + '<br />'); document.write('total inc gst; $' + htotal_tax + '<br />'); document.write('hordernumber; ' + hordernumber + '<br />');   </script> 

to display last value of array should use values[values.length-1].

this guarantee absolute last one.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -