In the provided code snippet, only the last value of .enter_form input
is being assigned to the last
MYAPP.list[0].responses[MYAPP.score.round].form[key]
, where the variable key
is the only element that changes. This issue seems to be caused by passing only the final key value to the addEntry()
function, but a solution to this problem has proven elusive.
$('.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();
}