lundi 12 juillet 2021

jQuery checkbox disable/enable with for loop

I want to disable all select input in the group by clicking a checkbox of the group.

    $(function(){
        for(var i = 0; i < 5; i++){
        enable_cb();
        $("#group_"+ i +"_check").click(enable_cb(i));
    });

    function enable_cb(i) {
        if (this.checked) {
            $("group-"+ i).find("select").attr("disabled", true);
        } else {
             $("group-"+ i).find("select").removeAttr("disabled");
        }
    }

For some reason this piece of code is not working.

Can anyone show me how to fix it?




Aucun commentaire:

Enregistrer un commentaire