Im having a hard time understanding the limits and possibilities of an IF statement. I just want to know the best and shortest way to write following. Essentially I just want to return false if an input is empty or if textarea still contains its default value. This form is name, email, phone and comments where phone is optional so I cant just target all inputs.
$('form').submit(function(){
if ( $('#email').val() == '') {
return false;
} else if ($('#name').val() == '') {
return false;
} else if ($('textarea').val() === 'Enter comments here.') {
return false;
}
});
This code works, but it takes up a bunch of space. Thanks!
Combine your conditions into a single logical statement, like this:
The bang symbol (!) is a NOT; it reverses the logic, returning false if any of the conditions succeed, and true if none of them succeed.