Skip to content

Instantly share code, notes, and snippets.

@fatadz
Last active September 30, 2023 08:45
Show Gist options
  • Save fatadz/9d45fdaccbac0a5c6251f80ac9120d9e to your computer and use it in GitHub Desktop.
Save fatadz/9d45fdaccbac0a5c6251f80ac9120d9e to your computer and use it in GitHub Desktop.
To check if multiple input fields are empty using vanilla JavaScript
// Get all the input fields
var inputs = document.querySelectorAll('input');
// Set a flag to track if any input fields are empty
var emptyFields = false;
// Loop through the input fields
for (var i = 0; i < inputs.length; i++) {
// Check if the current input field is empty
if (inputs[i].value === '') {
// Set the flag to true
emptyFields = true;
break;
}
}
// If the flag is true, at least one input field is empty
if (emptyFields) {
console.log('There are empty input fields');
} else {
console.log('All input fields are filled');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment