check if input empty on submit code example
Example 1: jquery check if input is empty on submit
var empty = true;
$('input[type="text"]').each(function() {
if ($(this).val() != "") {
empty = false;
return false;
}
});
Example 2: javascript form submit on button click check if required fields not empty
const checkEmpty = document.querySelector('#checkIt');
checkEmpty.addEventListener('input', function () {
if (checkEmpty.value &&
checkEmpty.value.length > 0 &&
checkEmpty.value.trim().length > 0
)
{ console.log('value is: '+checkEmpty.value);}
else {console.log('No value');
}
});