Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:40:28+00:00 2026-06-13T21:40:28+00:00

Im trying something simple below. I want to accept user input for their name

  • 0

Im trying something simple below. I want to accept user input for their name click a button save it and when the app loads a second time it displays the name.

Where am I going wrong below?

Do i need to put this code block somewhere else?

 <script type="text/javascript">

$(function(){
$('#saveButton').click(function() {
        window.localStorage.setItem("name", $('#name').val());
});
    $('#newpage').live('pageshow', function() {
        var personName = window.localStorage.getItem("name");
        if(personName.length>0){
                $('#name').val(personName);
        }
    });

});
</script>

Full html file

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="jquery.mobile-1.2.0.css" />
<script type="text/javascript" src="jquery-1.8.2.js"></script>
<script type="text/javascript" src="jquery.mobile-1.2.0.js"></script>


<script type="text/javascript">

$(function(){
$('#saveButton').click(function() {
        window.localStorage.setItem("name", $('#name').val());
});
    $('#newpage').live('pageshow', function() {
        var personName = window.localStorage.getItem("name");
        if(personName.length>0){
                $('#name').val(personName);
        }
    });

});
</script>


<title>Hello World</title>
</head>
<body>
<div id="home" data-role="page">
    <div data-role="header">
        <h1>
            Home Page</h1>
    </div>
    <div data-role="content">
        hello Phone Gap and JQuery Mobile! <a href="#newpage" data-role="button">new page</a>
    </div>
    <div data-role="footer" data-position="fixed">
        <h4>
            footer</h4>
    </div>
</div>


<div id="newpage" data-role="page">
    <div data-role="header">
        <h1>
            new Page</h1>
    </div>
    <div data-role="content">
        <label for="name">what is your name?</label>
        <input id="name" type="text" name="name" value="" />
        <a id="saveButton" href="" data-role="button">Save</a>
    </div>
    <div data-role="footer" data-position="fixed">
        <h4>
            footer</h4>
    </div>
</div>
<script type="text/javascript" src="cordova-2.1.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
    app.initialize();
</script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:40:29+00:00Added an answer on June 13, 2026 at 9:40 pm

    Yes, you need to place the button click event hookup in the pageinit event – they even specify this in the docs

    $(document).on("pageinit","#newpage",function(){
        $('#saveButton').click(function() {
            localStorage.setItem("name", $('#name').val());
        });
    });
    
    
    $(document).on('pageshow','#newpage', function() {
        var personName = localStorage.getItem("name");
        if(personName.length>0){
                $('#name').val(personName);
        }
    });
    

    For iOS device testing: In case your changes do not reflect on your device, make sure to touch your files before you deploy. Phonegap’s default project template already does this, but their command does not work for me. See my answer: https://stackoverflow.com/a/12707386/561545

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do something really simple here. All I want to do
I am trying to do something really simple here. All I want to do
Just trying to get into JQueryMobile. I want to do something simple like putting
I want a simple filter form, and a table below it. When the user
I'm trying something very simple. Upon page load the data in content div is
actually I thought I was trying something really simple. ControllerClassNameHandlerMapping sounded great to produce
I'm trying to do something simple in JSF but I can't get it working
I feel like I'm trying to do something simple but I am not getting
Hey guys, I've been trying to build something simple in Flash 8, and I
I'm trying to do something very simple, yet I can't seem to find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.