-1
<input type="checkbox" value="1"  />
<input type="checkbox" value="2" />
<input type="checkbox" value="3"  />
<input type="checkbox" value="4" />
<input type="checkbox" value="5"  />
<input type="checkbox" value="6" />
<input type="checkbox" value="7"  />
<input type="checkbox" value="8" />
<input type="checkbox" value="9"  />
<input type="checkbox" value="10" />

 FilterArray=[
{member_Key: 1},
{member_Key: 4},
{member_Key: 7},
   ]

I want to check the all the checkboxs inisde based on the FilterArray. It should check the checkbox on the page load.

2
  • 1
    i don't see any code that tries to do what you want Commented Nov 3, 2015 at 13:06
  • The checkbox has to select automatically based on array value Commented Nov 3, 2015 at 13:07

2 Answers 2

0

You can loop through the array, and then use the attribute selector method for getting the checkbox with a particular value.

$.each(FilterArray, function (index, value) {
    $("input[type='checkbox'][value=" + value.member_Key + "]").prop("checked", true);
});

Fiddle

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

$(document).ready(function () {
    var FilterArray = [1, 4, 7];
    $('#myForm').find('input').each(function () {
        $(this).prop("checked", ($.inArray(parseInt($(this).val()), FilterArray) != -1));
    });
});

Here is Fiddle Link

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.