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 7164203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:02:04+00:00 2026-05-28T14:02:04+00:00

I have a simple web mobile app that is calculating values in given fields.

  • 0

I have a simple web mobile app that is calculating values in given fields. I’ve been trying to save the values on the local host in the browser and haven’t had any luck. I am using jQuery to save the values, but somehow it doesn’t work.

     <script>
    $(document).ready(function() {
$('#field_wc').val(localStorage.getItem('wc') );
$('#field_tax').val(localStorage.getItem('tax') );
$('#field_sui').val( localStorage.getItem('sui') );
$('#field_o').val( localStorage.getItem('o') );
$('#field_fp').val( localStorage.getItem('fp') );
$('#field_misc').val( localStorage.getItem('misc') );
$('#field_t').val( localStorage.getItem('t') );


    });

    $('#field_tax').keyup(function() {
$('#field_wc').val( localStorage.setItem('wc') );
$('#field_tax').val( localStorage.setItem('tax') );
$('#field_sui').val( localStorage.setItem('sui') );
$('#field_o').val( localStorage.setItem('o') );
$('#field_fp').val( localStorage.setItem('fp') );
$('#field_misc').val( localStorage.setItem('misc') );
$('#field_t').val( localStorage.setItem('t') );


    });
    </script>
  • 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-05-28T14:02:05+00:00Added an answer on May 28, 2026 at 2:02 pm
    $(document).ready(function() { 
      var
        key,
        fields = ['wc', 'tax', 'sui', 'o', 'fp', 'misc', 't'];
    
      for(key in fields) { 
        (function (){
          var
            name = fields[key],
            field = $('#field_' + name)
              .val(localStorage.getItem(name) || '')
              .on('keyup', function() {
                localStorage.setItem(name, field.val());
              });
        }());
      }
    });
    

    Hi! I optimized your script and fixed a few other problems with it: http://jsfiddle.net/q78d8/4/

    • Using locally scoped variables to store the jQuery objects in is the biggest performance improvement. In your original script you made jQuery create those over and over again, for every keyup event fired
    • I think you wanted to bind each input to the “Save” function, but realize, you don’t have to update values which haven’t changed! If the user updated #field_tax, only save that value
    • Remember you can Chain jQuery methods
    • I used a little trick here, where I know that the return value of each chain, would still be the jQuery object I originally selected, so I could store the object in the same line in which I assigned a keyup handler on it & filled the value with what was in the localstorage
    • I wrapped the whole thing in a for loop, and an self-invoking function, to create an easy-to-do-maintenance-on script

    Edit —
    I left out that you used setItem incorrectly, since others already told you.

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

Sidebar

Related Questions

I have a simple web page that till now didn't need any login. It
I have a simple web service that uses an oracle database. When I test
I have a simple web service that has an API third party developers are
I have a simple web app with users and posts. I have an index
I have a simple web app built in asp.net webforms c# where and how
I have a simple web site ( http://www.kousenit.com/twitterfollowervalue ) that computes a quantity based
I have a simple web app: a web page with a form to submit,
I have a simple web-API accessible over HTTP with some corresponding mobile apps reading
I have a simple app developed with jQuery Mobile and implemented in PhoneGap. It
We have an existing web app built with jQuery Mobile. Our goal is to

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.