dimanche 18 octobre 2015

Checbox Limiter disabled problems

<input type="checkbox" value="1" name="malzeme1[]" checked="" disabled="" id="checkboxExample1" onclick="checkNumChecked(this, 2)">
<label for="checkboxExample1">Soğan<b class="product-subtitlex"> | + 1 ₺</b>
</label>
<input type="checkbox" value="3" name="malzeme1[]" id="checkboxExample3" onclick="checkNumChecked(this, 2)">
<label for="checkboxExample3">Soğanx<b class="product-subtitlex"> | + 1 ₺</b>
</label>

<input type="checkbox" value="4" name="malzeme1[]" id="checkboxExample4" onclick="checkNumChecked(this, 2)">
<label for="checkboxExample4">Soğanc<b class="product-subtitlex"> | + 1 ₺</b>
</label>

<input type="checkbox" value="5" name="malzeme1[]" id="checkboxExample5" onclick="checkNumChecked(this, 2)">
<label for="checkboxExample5">Soğanxc<b class="product-subtitlex"> | + 1 ₺</b>
</label>

<script>
  function checkNumChecked(ele, limit) {
    var ct = 0,
      siblings = document.getElementsByName(ele.name),
      checked = 0;
    for (ct = 0; ct <= siblings.length - 1; ct++) {
      checked += (siblings[ct].checked) ? 1 : 0
    }
    for (ct = 0; ct <= siblings.length - 1; ct++) {
      siblings[ct].disabled = siblings[ct].checked ? false : (checked == limit) ? true : false
    }
  }
</script>

This is mine Checkbox Limiter. For example it ll other checkboxes going disabled when I pick 2 checkbox. But there is a problem here when I after uncheck 1 checkbox forexample. It will remove original disabled="" checkbox too. It dont have to remove original disabled="" code




Aucun commentaire:

Enregistrer un commentaire