I need to check all the inputs to see if they are filled, in which case the submit button would become pressable and the user can submit their data safely:
unfilled = false;
$('.add-field').keypress(function(){
$('.add-field').each(function(){
if($(this).val() === ''){
unfilled = true;
} else {
unfilled = false;
}
})
console.log(unfilled);
});
This code works, but it has a strange twist; as the last empty input gains a character, it still returns true
. If an input gains another character, only then it will return false
. I am confused by this, as I understand that the .each()
function is fired after a character has been added and the value of the input has been updated. Consequently, I do not see why it does not register that value.