mercredi 6 mai 2015

JQuery Linked checkbox and use of function "each()

I'm posting here because i cant find any solution. I'm not a native speaker so i'll do my best to explain my problem.

There is what i call "checkboxs mother". If they are checked, their sons are disabled. I want to do a "clean" code, that's why i tried to user .each() but it didnt work as i wanted. Here my javascript code:

<script type="text/javascript">
        $(function() {

                $("#check_prev").each(function(){
                    this.click(enable_cb(i));
                    i++;
                });


            });

            function enable_cb(id) {
            if (this.checked) {

                $("input.input_panne"+id).attr("disabled", true);
                $("input.input_panne"+id).attr("checked",false);
                $("span.check_panne"+id).css("color", "#D8D8D8");

            } else {
                $("input.input_name"+id).removeAttr("disabled");
                $("span.check_agent"+id).css("color", "black");

                $("input.input_panne"+id).removeAttr("disabled");
                $("span.check_panne"+id).css("color", "black");

            }
        }   
</script>

I already tried ".concat()" but it's not working. Also the "checkbox mother" are named like this : check_prev1, check_prev2 etc. Sons, like this : input_panne1, input_panne2.

Thanks for your help... working on it for almost 2 days and no solution in sight ... gonna kill my self




Aucun commentaire:

Enregistrer un commentaire