I have an HTML page with several forms (created dynamically), so I get them in JS into an array, and then I add an EventListener
to each one, like this:
var forms = document.getElementsByTagName('form');
for(i=0; i < forms.length; i++) {
forms[i].addEventListener('change', function(){
checkAllFilled(i);
});
}
So in function checkAllFilled
I do some stuff.
The problem is that if I have 7 forms (from forms[0]
to forms[6]
) and I work over forms[2]
, it is always called checkAllFilled(7)
, instead of calling checkAllFilled(2)
. It's like the variable i
was set in the last value over the for loop.
How would I do this?
Thanks!