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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:48:34+00:00 2026-05-24T01:48:34+00:00

for (var key in obj[i]) { dataDump[key] = textField.value; textField.addEventListener(‘change’, function (e) { dataDump[key]

  • 0
for (var key in obj[i]) {
    dataDump[key] = textField.value;
    textField.addEventListener('change', function (e) {
        dataDump[key] = e.source.value;
    })
}

I am associating each key in my Object to the TextField which it get’s mapped. Now when i change the TextField….. the value get’s stored in the last key instead of key associated with the textField…

I am changing the TextField One… whose key is dataDump['FirstKeyName'], but it get’s store in the dataDump[‘LastKeyName’]…

  • 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-24T01:48:35+00:00Added an answer on May 24, 2026 at 1:48 am

    that’s normal. You are using a closure. So when you have the callback on change, it searches for key. But you have already finished iterating through obj and key equals the last “entry” of obj.

    To correctly associate the key you can do this :

    for (var key in obj[i]) {
        dataDump[key] = textField.value;
    
        var callback = function(zeKey){
         return function(e){
          dataDump[zeKey] = e.source.value;
         }; 
        }(key);
    
        textField.addEventListener('change', callback);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function: function myfunc(obj, properties, value) { $.each(properties, function(i, key) { var
function countJSONObjByKeyValue(obj, key, value) { var countJSONShows = 0; $.each(obj, function(i, item) { if(obj[i].key
var myNewKeyNames = ['asas','asas']; var obj =[{key:'value',key:'value'}] for(var i =0; i<obj.length; i++) { for(key
Let's asume that I have an object: var obj = {A:a, B:b, x:y, a:b}
For example I have this plugin code: jQuery.fn.keys = function(obj) { var keys =
I have a function that takes a parameter(key) to retrieve it's value from a
Question about the implementation of the each function I found in the underscore.js source
var obj = { func: function() { return: { add: function() { } }
Currently I'm using var x = dict.ContainsKey(key) ? dict[key] : defaultValue I'd like some
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();

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.