Checking values in this array, JQuery

Posted by Felix Guerrero on Stack Overflow See other posts from Stack Overflow or by Felix Guerrero
Published on 2010-05-29T03:16:27Z Indexed on 2010/05/29 3:22 UTC
Read the original article Hit count: 238

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about arrays