Your case can be solved by replacing the for loop and adding a function:
for (var i=0; i<inputs.length; i++) {
attachCheck(inputs[i]);
}
function attachCheck(inp) {
inp.addEventListener('input', function() {
check(this);
});
}
Wouldn't it be better though to modify check()
to use this
, like:
function check() {
if(this.value.length) {
// ... all elm replaced by this ...
}
And the loop:
for (var i=0; i<inputs.length; i++) {
inputs[i].addEventListener('input', check);
}