1

I have one array with checkboxes values. For example 2,5,9 .... This is my array:

var values = params['Values'];

And then I need cycle for all checkboxes with current class and set checkboxes if their value in array.

for (var i = 0; i < values.length; i++) {
        $(":checkbox[name=Current][value='values[i]']").prop("checked", "true");
    }

But its not working(

2
  • Can you please include why it is "not working" Commented Nov 25, 2016 at 13:35
  • I dont know. Nothing heppens Commented Nov 25, 2016 at 13:36

2 Answers 2

1

values[i] is in a string in your example. Try this:

for (var i = 0; i < values.length; i++) {
        $(":checkbox[name=Current][value=" + '\'' + values[i] + "']").prop("checked", "true");
    }

Hope that helps!

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

Comments

0

Maybe this is what you want. Try this..

$(document).ready(function(){
  
  var value = [1,5,6];
  
  value.forEach(function(item, index){
    var idCB = '.cb'+value[index]; 
    $(idCB).prop('checked','true')
  });

})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" class="cb1" value="cb1">CB1
<input type="checkbox" class="cb2" value="cb2">CB2
<input type="checkbox" class="cb3" value="cb3">CB3
<input type="checkbox" class="cb4" value="cb4">CB4
<input type="checkbox" class="cb5" value="cb5">CB5
<input type="checkbox" class="cb6" value="cb6">CB6

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.