Looking to streamline my code by creating a function that checks if an input field is empty before sending the data to Php via Ajax. The function should return true or false and display an error message if needed. However, I'm facing an issue when dealing with two fields in the if statement. Here's what I have so far:
const email = document.getElementById('username');
const password = document.getElementById('password');
if(verifyInput(email) && verifyInput(password)) {
console.log('Ready');
}
The problem arises when one field is empty, as the function call for the second field does not get executed.
To work around this issue, I've resorted to using a multiplication operation:
if(verifyInput(email) * verifyInput(password)) {
console.log('Ready');
}
I'm curious if there is a more efficient solution to handle this situation.
Thanks!