0

Okay so I've read this closure question and tried to fit the idea behind my script. This is what I have so far but the console is telling me that nameOfLoan[j] does not exist and I can't figure out why.

$('body').on('keyup', '.qForms', function() {
var nameOfLoan = [];

 var loanOfName = function(t) {
   $('body').on('keyup', '.loanNameV'+t, function() {
     console.log('hi');
    var loanN = $('.loanNameV'+t).val();
    $('.nameLoan'+t).text(loanN);
   });
  };

 for (var t=1; t < z; t++) {
  nameOfLoan[t] = loanOfName(t);
 }

 for (var j=1; j < z; j++) {
  nameOfLoan[j]();
 }
});
Community
  • 1
  • 1
Frank
  • 73
  • 1
  • 1
  • 5
  • 2
    Is `i` defined at `for` loop ? – guest271314 May 04 '15 at 23:21
  • Not based on what is here. What is `i`? – colecmc May 04 '15 at 23:21
  • 3
    At `nameOfLoan[t] = loanOfName[t];`, but `loanOfName` is a function. –  May 04 '15 at 23:22
  • i is defined earlier on in my script before this section and it =s 2 to begin with but can increase and decrease depending on how many dynamically created elements there are @colecmc – Frank May 04 '15 at 23:29
  • extra function inside `loanOfName()` isn't needed either. `loanOfName(t)` creates a closure for the code inside it – charlietfl May 04 '15 at 23:31
  • Seems like we're missing some pieces. Can you provide a full snippet? Or post the code to jsbin? – colecmc May 04 '15 at 23:31
  • What is `z` ? What is expected result ? – guest271314 May 05 '15 at 00:25
  • @guest271314 I have dynamically created elements that I want to apply a keyup function to. Essentially everytime you write in one of the text forms of a dynamically created elements the text inside the "title" of these elements changes to whatever is being typed in the text form – Frank May 05 '15 at 00:36
  • Tried with only first `keyup` event ? Can include example `html` ? – guest271314 May 05 '15 at 01:08

0 Answers0