I am creating a web page where the user and select an item by clicking on the button. The details of the item selected will be displayed in a dropbox. At the moment I can get it to update the quantity if the user selects it again. The problem which I am having is, say if the user first click on btnBuy1 (details displayed in dropbox), then clicks on btnBuy2 (again, details are displayed), but when they click on btnBuy2 again , the details from btnBuy2 is updated but the details from btnBuy1 disappears.
$("#btnBuy0").click(function()
{
if (!sessionStorage['quantity0'])
{
sessionStorage['quantity0'] = 1;
$("#dropbox").append('<span id = "0"><img class = "thumb" src="../images/21_metoyou.jpg" />' + teddy[0].desc + ", Price £"
+ teddy[0].price + ", Quantity: " + sessionStorage.getItem('quantity0') + "</span><br/>");
}
else
{
sessionStorage['quantity0']++;
$("#dropbox").html('<span id = "0"><img class = "thumb" src="../images/21_metoyou.jpg" />' + teddy[0].desc + ", Price £"
+ teddy[0].price + ", Quantity: " + sessionStorage.getItem('quantity0') + "</span><br/>");
}
if (Modernizr.sessionstorage)
{ // check if the browser supports sessionStorage
myids.push(teddy[0].partnum); // add the current username to the myids array
sessionStorage["ids"]=JSON.stringify(myids); // convert it to a string and put into sessionStorage
}
else
{
// use cookies instead of sessionStorage
}
});
$("#btnBuy1").click(function()
{
if (!sessionStorage['quantity1'])
{
sessionStorage['quantity1']=1;
$("#dropbox").append('<span id = "1"><img class = "thumb" src="../images/birthday_metoyou.jpg" />' + teddy[1].desc + ", Price £"
+ teddy[1].price + ", Quantity: " + sessionStorage.getItem('quantity1') + "</span><br/>");
}
else
{
sessionStorage['quantity1']++;
$("#dropbox").html('<span id = "1"><img class = "thumb" src="../images/birthday_metoyou.jpg" />' + teddy[1].desc + ", Price £"
+ teddy[1].price + ", Quantity: " + sessionStorage.getItem('quantity1') + "</span><br/>");
}
if (Modernizr.sessionstorage)
{ // check if the browser supports sessionStorage
myids.push(teddy[1].partnum); // add the current username to the myids array
sessionStorage["ids"]=JSON.stringify(myids); // convert it to a string and put into sessionStorage
}
else
{
// use cookies instead of sessionStorage
}
});