Skip to content Skip to sidebar Skip to footer

Check Checkboxes Based On Values In An Array

Checkbox check with Array or values Html Code:
$('#'+f.join(', #')).prop('checked', true);

FIDDLE

Solution 2:

With the forEach method of Array this is very simple even without JQuery.

f.forEach(function(i){
  document.getElementById(i).checked = true;
});

You can read more about for each on the Mozilla Developer Network

Solution 3:

One simple way is iterate over the array and use prop method along with id selector.

for(var i=0;i<f.length;i++) {
    $('#' + f[i]).prop('checked', true)
}

Check Fiddle

Post a Comment for "Check Checkboxes Based On Values In An Array"