monkey
monkey

Reputation: 3

jquery array how to get a key that has an empty value

i have an array with some keys and values pair.

i'm checking if there is a key that has empty value and if so I would like to know how to get this key :

$(form).on('submit',function() {
    var arr          = {};
    var elemRequired = $(this).find('input:not(input[type=button], input[type=submit], input[type=reset]),textarea,select,checkbox').filter(':visible');
    $('.error').empty();
    elemRequired.each(function(i, el) {
        arr[el.id] = el.value;
    });
    $.each(arr, function(id, val) {
        if (val == ""){
    /*here i want to get the id that has the empty value*/      
            id.addClass('invalid');

        }else{

        }
    });

    return false;
});

i know ther might be other way to do this but i want to know if there's a way to do it like that

thanks for the help

Upvotes: 0

Views: 152

Answers (1)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Put this

 $('#'+id).addClass('invalid');

instead of this

id.addClass('invalid');

Upvotes: 1

Related Questions