Hi everyone.
First of all, sorry for my english, I know it not very good...
The application has two text fields (name and url). The user enters data into this fields. The application receives and stores the data in local memory like as follows:
<"user_data_0", "Tom">&<"Tom", "Tom's url">;
...
<user_data_N, "Jerry">&<"Jerry", "Jerry's url">;
That's how I try to do this:
function addData(){ var name = document.getElementById("name").value; var url = document.getElementById("url").value; var next_number; next_number=localStorage.getItem('next');//"next" is a value of next number for adding if(next_number){ var key_name = "user_data_"+next_number; next_number++; } else { var key_name = "user_data_0"; next_number=1; } /* Set the local storage item */ if("localStorage" in window){ localStorage.setItem(key_name,name); localStorage.setItem(name,url); localStorage.setItem('next',next_number); } }
Then I tried to pull data from locale:
var i = 3;// it's for example. I will receive values in the loop alert(localStorage.getItem("user_data_"+i));
But when I started testing, it's returned data from localstorage with key "next". Why? And as it can be corrected?
Thanks.