lundi 18 mai 2015

jquery if checkbox is checked disable other specific checkboxes in based on value

Here what i need is,

<div id="employeedetails-relation" class="check"><div class="checkbox">    <label><input type="checkbox" name="Employeedetails[relation][]" value="1"> Father</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="2"> Mother</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="3"> Spouse</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="4"> Child1</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="5"> Child2</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="6"> Father-in-law</label></div>
<div class="checkbox"><label><input type="checkbox" name="Employeedetails[relation][]" value="7"> Mother-in-law</label></div></div>

here if i check value 1 or 2 then value 6 and 7 checkbox must get disable, and the same way if i check value 6 or 7 then checkbox value 1 and 2 must get disable.

suppose if i check value 3 first and then if i checked value 1 or 2. again value 6 and 7 must be get disable.

if i unchecked value 1 and checked value 2, again value 6 and 7 must be get disable, alternatively

mycode:

$(\'input[type="checkbox"]\').click(function(){

        if (this.checked && this.value === "1") {
        $(\'#employeedetails-relation input[value="6"\').prop(\'disabled\', \'true\');
        $(\'#employeedetails-relation input[value="7"\').prop(\'disabled\', \'true\');
        } 
        elseif (!this.checked && this.value === "1")
        {
        $(\'#employeedetails-relation input[value="6"\').prop(\'disabled\', \'false\');
        $(\'#employeedetails-relation input[value="7"\').prop(\'disabled\', \'false\');
        }




Aucun commentaire:

Enregistrer un commentaire