mercredi 26 octobre 2016

checkbox enable disable based on dropdown option

i have created a dropdown and few checkboxes. checkboxes enable and disable based on dropdown option selected.

here is the code:

<select id="Objective" form="theForm" name="category" >
    <option value="pi">Pipi</option>
    <option value="theta">thethaatha</option>
    <option value="sigma">sigmama</option>
</select>
<div>
<input type="checkbox" class="dissable" onclick="check();" value="1" /> Teas<br>
<input type="checkbox" class="dissable" onclick="check();" value="1" /> Capri<br>
<input type="checkbox" class="dissable" onclick="check();" value="2" /> Kids <br>
<input type="checkbox" class="dissable" onclick="check();" value="2" /> Food <br>
</div>

<script>
$("#Objective").on("change", function () {
    if ($(this).val() == "theta") {
        $(".dissable[value='1']").prop("disabled", true);
    } else if ($(this).val() == "pi") {
        $(".dissable[value='2']").prop("disabled", true);
    } else {
        //donothing
    }
}).trigger('change');
</script>

whenever i chose pi fron dropdown it goes fine both value = "2" kids and food gets disabled but when i chose thetata from every checkbox gets disabled which should not be like this. only value ="1" should get disabled i.e., teas and capri.

help correcting it whats the problem with code. thanks in advance.




Aucun commentaire:

Enregistrer un commentaire