0

In my application, I have 2 pages, page1 and page2. In page1, I have one text field and one label. I want to pass these two values from page1 to page2 and to insert them as text for 2 labels respectively when click on submit button. I'm new to Phonegap and jQuery. How can i achieve this using jQuery and Javascript?

{
    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");
    fullnameLabel.innerHTML = getname.value;  //label
    userNameLabel.innerHTML = getusername.value;  //label
}
user25
  • 141
  • 2
  • 3
  • 12

3 Answers3

3

You can use localStorage to achieve this. New in HTML5, it allows for persistent storage client-side.

localStorage uses key/value pairs.

localStorage.setItem("Key-name", itemData);

localStorage.getItem("Key-name");

localStorage.removeItem("Key-name");

ahren
  • 16,803
  • 5
  • 50
  • 70
  • Do i need to write all these in javascript file? – user25 Jun 05 '12 at 06:13
  • only the bits you need. I was just saying there are three methods available to you (set, get, remove). But yes, they are javascript. – ahren Jun 05 '12 at 06:14
  • @user25 Then I suggest posting your code so people can help you by troubleshooting. – ahren Jun 05 '12 at 09:31
  • 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"); fullnameLabel.innerHTML = getname.value; //label userNameLabel.innerHTML = getusername.value; //label – user25 Jun 06 '12 at 05:56
1

Make use of localStorage.It is the best option to transfer the data between pages

read about it here http://docs.phonegap.com/en/1.7.0/cordova_storage_storage.md.html#localStorage

coderslay
  • 13,960
  • 31
  • 73
  • 121
1

If you just want to pass simple text data you can also use query parameters (home.html?text=test).

Here a link how to get there parameters in javascript: How can I get query string values in JavaScript?

This way is maybe a little bit faster because you dont have to use the js bridge and file IO on the device... but it should not realy matter =)

Community
  • 1
  • 1
Dominik Kirschenhofer
  • 1,205
  • 1
  • 13
  • 27