mercredi 7 février 2018

How to set certain checkbox to disabled based on given array?

I have an array of comma separated string. This will determined whick checkbox should be disabled.

var lbl = "A,C";

Then I want to compare it on the checkboxes in the form. The check boxes values are A,B,C,D.

Based on the string given, the checkbox which value are A and C should be disabled.

This is my current script:

$('#f_sendTo input[type=checkbox]').each(function() {

    var arr_cek_txt = $(this).val().split('||');   //This is checkboxes value
    var arr_lbl_ext = lbl.split(',');              //this is the string = "A,C"

    var val_lbl_ext;

    $.each(arr_lbl_ext,function(i){


        if(arr_cek_txt[1] == arr_lbl_ext[i]){

            $(this).prop("disabled", true);
        }           
    });                 
});




Aucun commentaire:

Enregistrer un commentaire