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
-
do you want to add invalid class to element which has id empty?Bhushan Kawadkar– Bhushan Kawadkar2014年06月26日 11:01:53 +00:00Commented Jun 26, 2014 at 11:01
-
Is it working or not?Maurice Perry– Maurice Perry2014年06月26日 11:03:09 +00:00Commented Jun 26, 2014 at 11:03
-
yep that's what i wantmonkey– monkey2014年06月26日 11:05:55 +00:00Commented Jun 26, 2014 at 11:05
1 Answer 1
Put this
$('#'+id).addClass('invalid');
instead of this
id.addClass('invalid');
answered Jun 26, 2014 at 11:02
Comments
lang-js