mardi 11 juillet 2017

How do this? If Checkbox is Disabled and Checked, It should always be disabled

I am working on Time Checking Calendar, At one point I need to put condition like if checkbox is checked and disabled, it would be always disable. So user can't uncheck it. For it, I had put following Condition. But it is not working.

if($(this).is(':checked') && $(this).is(':disabled')){
   $(this).attr("disabled", true);
}

This is the Code where I'm working.. [for more clear Idea about what i'm asking]

$('input[type="checkbox"]').on('change', function() {
  $(this).parent('label').nextAll('label').first().find('input[type="checkbox"]').prop('checked', $(this).is(':checked'));
 
$(this).parent('label').nextAll('label').first().find('input[type="checkbox"]').attr("disabled", $(this).is(':checked'));

$(this).parent('label').prevAll('label').first().find('input[type="checkbox"]').attr("disabled", $(this).is(':checked'));

 a= $(this).parent('label').prevAll('label').first().find('input[type="checkbox"]');
  
if(a.is(':checked')){
        a.attr("disabled",true);
}


if($(this).is(':checked')){ $(this).parent('label').prevAll('label').first().find('input[type="checkbox"]').attr("disabled", true);
}

if($(this).is(':checked') && $(this).is(':disabled')){
$(this).attr("disabled", true);
}


        


  
})
<script src="http://ift.tt/1oMJErh"></script>
<label><input type="checkbox" name="one" value="a"> 08:00</label><br/>
<label><input type="checkbox" name="one" value="b"> 08:30</label><br/>
<label><input type="checkbox" name="one" value="c"> 09:00</label><br/>
<label><input type="checkbox" name="one" value="c"> 09:30</label><br/>
<label><input type="checkbox" name="one" value="c"> 10:00</label><br/>
<label><input type="checkbox" name="one" value="f"> 10:30</label><br/>
<label><input type="checkbox" name="one" value="g" disabled> 11:00</label><br/>



Aucun commentaire:

Enregistrer un commentaire