I want to know if all conditions inside the for
-loop match, so that I can do something. However onChange()
is blocking me.
jQuery code:
var arrayLength = array.length;
var count = 0;
for ( var i = 0; i < arrayLength; i++ ) {
if(array[i].status == '0' ) {
jQuery("#"+array[i].field+"_field").on('change', ( function( dbvalue ) {
return function(e) {
if( e.target.value == dbvalue ) {
count++;
} else {
count--;
}
};
})(array[i].value));
}
}
I have used count
and if count
matches array.length
I want to do something. However with onChange()
being called, count
can decrease if value does not matches multiple times, hence the incorrect logic.
if(count == arrayLength) {
alert('success');
} else {
alert('Failure');
}
What could be the solution?
Aucun commentaire:
Enregistrer un commentaire