Last active
April 10, 2025 13:08
-
-
Save fatadz/9d45fdaccbac0a5c6251f80ac9120d9e to your computer and use it in GitHub Desktop.
To check if multiple input fields are empty using vanilla JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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