I have a massive problem, with little time to resolve it. I am creating my first mobile app for property search as a university project (its not based on real properties) I tried using different keys it does not work, Im not getting the basics. Basically I have a Jquery mobile app with many external pages which have details for a property, these pages have the same id but on different documents, When a user clicks the button to save, I want the title and the url of the page to be saved in local storage and to be retrieved by a third page called my favorites. The problem I am having is that when I go on each page and click save, it overrides what was already in local storage and it seems like each page has its own storage and as a result my favorites page always has only one favorite (the latest one), rather than a favorite list appending every time I click save. Here is my code:
<div data-role="header" id="samplePlacePage_hd">
<h4 id="hutRef">add#redHut456</h4>
</div>
<div data-role="main" id="samplePlacePage_cont">
<div id="image">
<a href="#"><img src="images/redhut.jpeg" height="200px" width="100%" alt="Hut"></a>
</div>
<div id="place_title">
<p id="hutHeading">Stunning Red Hut in Central Red Beach</p>
</div>
<div>
<h4 style="float: left;">Rent: $2950pw</h4>
<h4 style="float: right;">Deposit: 5500</h4>
</div>
(Same code on both pages) This was the function I had in my script file:
$(document).on("pagecreate",function (argument) {
var favoritesPlaces = [];
var heading = document.getElementById('hutHeading').innerText;
var ref = document.getElementById('hutRef').innerText;
var refLink = ref.replace("add#","");
document.getElementById('hutFav').onclick = function () {
var newFav = {
title: heading,
link: refLink
};
favoritesPlaces.push(newFav);
console.log(favoritesPlaces);
localStorage.setItem("favorites",JSON.stringify(favoritesPlaces));
}
})
Please help
Thanks