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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:40:24+00:00 2026-05-18T19:40:24+00:00

The following code is only assigning the value of the last .enter_form input to

  • 0

The following code is only assigning the value of the last .enter_form input to the last MYAPP.list[0].responses[MYAPP.score.round].form[key] (where key is the only thing that varies). I think it’s because only the last value of the key is being passed to addEntry(), but I can’t figure out how to get around that.

$('.enter_form input').each(function() {
    var key = $(this).attr('id');
    var val = $(this).val();
    userDict[key] = val;
    MYAPP.list[0].responses[MYAPP.score.round].form = [];
    function addEntry() {
        return function(k) {
            MYAPP.list[0].responses[MYAPP.score.round].form[k] =  {'entry': userDict[k]};
        }(key);
    }
    addEntry();
}
  • 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-18T19:40:25+00:00Added an answer on May 18, 2026 at 7:40 pm

    Your addEntry function is redundant since each iteration is already run inside it´s own scope so key and val are preserved properly (hope that explanation makes sense). Also the array you where inserting into was overwritten each iteration as well, so at the end of the .each() you end up with an array with only 1 value. It should also be an object rather then an array, even if the id’s are numerical.

    // you where overwriting this each iteration
    MYAPP.list[0].responses[MYAPP.score.round].form = {};
    
    $('.enter_form input').each(function() {
    
        var el= $(this); // cache instead of creating a new jQuery object each time
        var key = el.attr('id');
        var val = el.val();
    
        userDict[key] = val;
        MYAPP.list[0].responses[MYAPP.score.round].form[key] =  {'entry': userDict[key]};
    
    }); // ); was also missing
    

    Should work.

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

Sidebar

Related Questions

The following code only displays the last .text upadate. It works as expected with
What should I do to marshal an hash of arrays? The following code only
One recommends me the following code apparently only in .zshrc without explaining its purpose
I have multiple messages in SQS. The following code always returns only one, even
When I compile the following code, I only see the error during Run-time which
I used following code, but it displays only 2 digit of ISO country name.
When I run the following code, it only seems to be downloading the first
In following code, I have one large component, and I'd like only the level4
I have written the following code. But it is removing only &nbsp; not <br>
I have the following scenario. The client code only has access to FooHandler, not

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.