warhad warhad - 13 days ago 5
Javascript Question

Get Checkbox value And set

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(

Answer

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!