Using the util class above we can use its isEmpty and alertDiv function for validate form fields.
The function that I use in here will retrieve all the ids of a form input fields and textareas.
The id of each input field and textarea must be defined in the first placed. So, instead
of making a variable that points to each input. I store all the ids in an array.
Now you can skip all these and use the validate feature of jQuery. But I don't
want to do that because it removes all of the fun of programming.
The function
function emptyFormFieldValidation(formId) { var ids = $(formId).find("input:not([type=submit]), textarea"").map(function() { return this.id; }).get(); for(i = 0; i < ids.length; i++) { if(!$.trim($(ids).val()).length) { alert("Please complete this field: " + $(ids).attr("name")); return false; } } return true; }