You cannot return false from an anonymous function. Also, if that worked, you will return false if your first field was empty, true if not, and completely ignore the rest of the fields. There may be a more elegant solution, but you can do something like this:
function validateForm() { var isValid = true; $('.form-field').each(function() { if ( $(this).val() === '' ) isValid = false; }); return isValid; }
Another recommendation: this requires that you decorate all form fields with this formfield class. You may be interested in filtering using another selector, for example. $('form.validated-form input[type="text"]')
EDIT . Ah, I got hit, but my explanation is still relevant and hopefully helpful.
Guttsy
source share