javascript form submit on button click check if required fields not empty 1

javascript form submit on button click check if required fields not empty

const inputFeilds = document.querySelectorAll("input");

const validInputs = Array.from(inputFeilds).filter( input => input.value !== "");

console.log(validInputs) //[array with valid inputs]

Here is what the above code is Doing:
1. We select all the input fields on the page.
2. We create an array from the NodeList of input fields.
3. We filter the array to only include the input fields that have a value.
4. We log the array of valid input fields to the console.

Similar Posts