0

I have to bind the checkboxes on a page whose values match in a string containing comma separated values, i have done the opposite of this in jquery through map and join functions. Its a combination of individual checkboxes on the page.

2
  • Its a collection of individual checkboxes like this <input type="checkbox" value="2" name="xyz" class="checkbox" id="chbServiceDue" runat="server" checked="checked" /> Commented Dec 10, 2013 at 17:53
  • yah why am I not getting the checkmark? Did you not see what I put? Did you mean "state" or two-way binding? If just attaching state based on arr, I got that, holmes. Commented Dec 10, 2013 at 19:59

1 Answer 1

1
(function(){
  var arr = [4,6,2,7,2];
  for(var i = 0; i < arr.length; i++) {
    $('.checkbox[value=' + arr[i] + ']').prop('checked',true);
  }
})();
Sign up to request clarification or add additional context in comments.

1 Comment

Just to add, use quotes if the arr is string array. $('.checkbox[value="' + arr[i] + '"]').prop('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.