user25
user25

Reputation: 141

unable to set and get values in localstorage

I'm developing a web application in iPhone using Phonegap. In this app, I want to send data from one page to another within the same index.html file. I'm using local storage to send data, but I am unable to send values. whenever the local storage statements are encountered, it skips the remaining statements also in that javascript function. Please tell me the solution. Do I need to add any plugin to use local storage?

{
    var name = document.getElementById("usernameTextField").value;   //TextField of page1
    var fullname = document.getElementById("nameLabel").innerHTML;  //label of page1
    localstorage.setItem("userName", name);
    localstorage.setItem("fullname1", fullname); 
    var getusername = localstorage.getItem("userName");
    var getname = localstorage.getItem("fullname1");
    fullnameLabel.innerHTML = getname.value;  //label of page2
    userNameLabel.innerHTML = getusername.value;  //label of page2
}

Upvotes: 2

Views: 1074

Answers (1)

dhaval
dhaval

Reputation: 7659

Try with this

{
    var name = document.getElementById("usernameTextField").value;   //TextField
    var fullname = document.getElementById("nameLabel").innerHTML;  //label
    localStorage.setItem("userName", name);
    localStorage.setItem("fullname1", fullname); 
    var getusername = localStorage.getItem("userName");
    var getname = localStorage.getItem("fullname1");
    alert(getname + " " + getusername);  //label

}

Please check the full code here

Upvotes: 1

Related Questions