warhad warhad - 1 year ago 113
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 Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download