0

I have an javascript array filled with values of checkboxes in a html file. How can i find the specific element and change checksign from jquery.

jQuery.each(substr, function() {
 var n = this;
 $('input[type=checkbox]').each(function () {
 $('input[name='+n+']').attr('checked', true);
 });
});

Substr is the array filled with names. substr = {'a', 'b', 'c', 'd'} .The above code does not work. please help

1 Answer 1

2

I think substr = {'a', 'b', 'c', 'd'} should be substr = ['a', 'b', 'c', 'd'].

jQuery.each(substr, function(i, val) {
 // val = a, b, c... etc
 $('input[type=checkbox][name="'+ val +'"]').attr('checked', true);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, added like that only for display purpose ;)
it worked like this jQuery.each(substr, function(i, val) { $('input[type=checkbox][value="'+ val +'"]').attr('checked', true); });

Your Answer

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.