Reputation: 17
I have a form that will push items into a multi-dimensional array, but I don't know how to save it to a cookie to be called back again later upon reloading the page.
function addit(form) {
upperlimit = upperlimit + 1
original[original.length++] = new input(form.Title.value, form.Artist.value, form.Ddate.value, form.Genre.value, form.Picsrc.value)
alert("your entry has been added")
saveIt()
clearform()
}
Cookie function?
function saveIt() {
var x = original;//this is a multi-dimensional array
$.cookie("data",original);
alert($.cookie("data"));}
need to somehow call back and load the cookie into the array to be able to carry out a display:
$("#info").html(original[currentrecord].Title+"<br /><h2>"+original[currentrecord].Artist+"</h2>"+original[currentrecord].Ddate+"<br />"+original[currentrecord].Genre) ;
By the way, when I just do an alert for the array ( alert(original) ), it shows up as [object Object] if that influences what is being saved to the cookie?
Upvotes: 0
Views: 1453
Reputation: 76405
before writing your object to a coockie (it's an object, not an array), just do this
var x = JSON.stringify(original);
To use it as an object again:
var back2orig = JSON.parse($.cookie('data'));
That's all there is to it... google JSON, you'll love it :)
Upvotes: 4