I am trying to get the amount of objects saved to a session storage element.
I need to find out how many tickets have been saved into session storage; tickets.
So far the code I have is;
$('#price').html(sessionStorage['tickets']);
I have tried sessionStorage.length['tickets']);
and a few other variations to no avail.
I am aware this is a simple request but have trawled the internet and haven't gotten far.
This function created sessionStorage tickets by passing a class into it.
function confirm(){
var str="";
if(!sessionStorage['user']){
alert('You Must First Sign In or Register!');
} else{
if($(".tickets").length>0){
$(".tickets").each(function(){
str += this.id+" ";
sessionStorage.setItem('tickets', str);
});
} else {
alert("You have not sellected any seats.");
}
//alert(""+sessionStorage['tickets']);
window.location="index.php";
}
}
If you want get the number of tickets you can use this code:
sessionStorage.getItem ('tickets').split (' ').lenght
Regards, Kevin