0

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

asked Jun 26, 2014 at 10:57
3
  • do you want to add invalid class to element which has id empty? Commented Jun 26, 2014 at 11:01
  • Is it working or not? Commented Jun 26, 2014 at 11:03
  • yep that's what i want Commented Jun 26, 2014 at 11:05

1 Answer 1

1

Put this

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

instead of this

id.addClass('invalid');
answered Jun 26, 2014 at 11:02

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.