Skip to content Skip to sidebar Skip to footer

Checbox Limiter Disabled Problems

Solution 1:

What I have done here in order to permanently disable the check box you want the code to leave alone is to use a custom data attribute "data-permdisable". This tells the code to skip making any changes to the element.

Also, I should point out that you should have checked="checked" and disabled="disabled" as a matter of form.

<inputtype="checkbox"value="1"name="malzeme1[]"checked="checked"disabled="disabled"id="checkboxExample1"onclick="checkNumChecked(this, 2)"data-permdisable="true"><labelfor="checkboxExample1">
    Soğan<bclass="product-subtitlex"> | + 1 ₺</b></label><inputtype="checkbox"value="3"name="malzeme1[]"id="checkboxExample3"onclick="checkNumChecked(this, 2)"><labelfor="checkboxExample3">
    Soğanx<bclass="product-subtitlex"> | + 1 ₺</b></label><inputtype="checkbox"value="4"name="malzeme1[]"id="checkboxExample4"onclick="checkNumChecked(this, 2)"><labelfor="checkboxExample4">
    Soğanc<bclass="product-subtitlex"> | + 1 ₺</b></label><inputtype="checkbox"value="5"name="malzeme1[]"id="checkboxExample5"onclick="checkNumChecked(this, 2)"><labelfor="checkboxExample5">
    Soğanxc<bclass="product-subtitlex"> | + 1 ₺</b></label><script>functioncheckNumChecked(ele, limit) {
      var ct = 0,
      siblings = document.getElementsByName(ele.name),
      checked = 0;
        for (ct = 0; ct <= siblings.length - 1; ct++) {
            checked += ((siblings[ct].getAttribute("data-permdisable") == "true") ? 0 : ((siblings[ct].checked) ? 1 : 0))
        }
        for (ct = 0; ct <= siblings.length - 1; ct++) {
            siblings[ct].disabled = (siblings[ct].getAttribute("data-permdisable") == "true") ? 
                siblings[ct].disabled : siblings[ct].checked ? false : (checked == limit) ? true : false
        }
    }
</script>

Post a Comment for "Checbox Limiter Disabled Problems"