Checking values in this array, JQuery
- by Felix Guerrero
Hi.
I have this array (JQuery) where I add all my form's controls, it looks like:
var name = $("#name"),
surname = $("#surname"),
address = $("#address"),
phone = $("#phone"),
photo = $("#photo"),
grade = $("#grade"),
profession = $("#profession"),
email = $('#email'),
title = $('#title'),
allFields = $([]).add(name)
.add(surname)
.add(address)
.add(phone)
.add(photo)
.add(grade)
.add(profession)
.add(email)
.add(title)
.add(grade);
I want to check the values of each element into the 'allFields' array with
function checkingFieldsArentEmpty(){
var valid = true;
for (var f in allFields){
if(allFields[f].val() === null)
//if any val is null just return false
return false;
}
//true
return valid;
}
I need ideas in order to improve the last function. Thanks.