Set multi checkbox element with jQuery

deant

Active Member
Hi,

New day brings a new challenge. Hers is my problem: In repeat group I have dbjoin element and multi checkboxes. When user select Item in dbjoin element in same group I like to set checkbox element depending on Ajax result. I can get the proper values for checkbox element...but I can't find proper method to set which checkbox is checked. Here is what I have for now:

JavaScript:
// console.log(value_chk);  // from userAjax we get ["1","3"]

for (var i = 0; i < value_chk.lenght; i++) {
        jQuery('input[type=checkbox]' + elem_chk.element.id + '[value="'+value_chk[i]+'"]').prop('checked', true);
}



Any sugestions?
 
I found a solution...

What we get from userAjax e.g. ["1","2", "4"] convert to JS array. JS array looks something like (3) ["1", "2", "4"] it is very similar as JSON data but it is not the same.

So if anybody need a solution here is the code:
JavaScript:
var my_array = ["1", "2", "4"];
jQuery.each(my_array, function (index, value) {
     jQuery('#my_table_123_repeat___my_checkbox_' + repeat + ' [value="' + value.toString() + '"]').prop("checked", true);
});

Another thing to mention is s space between ' and [value.... I spent 2 hours to to find it.

If your element not in repeat group

JavaScript:
jQuery('#my_table_123_repeat___my_checkbox [value="' + value.toString() + '"]').prop("checked", true);

@troester
thanks for all your hard work and time you put into this comunity. Even if you don't have a first-hand solution you always pointing people to right direction,
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top