This question already has an answer here:
- Remove attribute “checked” of checkbox 9 answers
I have 5 checkbox and only the first checkbox is not disabled. I want to remove disabled attribute when i checked the first checkbox from remaning checkbox and when i checked the second checkbox then the 3,4,5 checkbox get checked and if i remove the checked from first checkbox then all other checkbox also remove there checked property and get disabled.
function showdis(a){
if(a.checked==true){
for(i=2;i<=5;i++){
$('#pay'+i).removeAttr("disabled");
}
}else{
for(i=2;i<=5;i++){
$('#pay'+i).removeAttr("checked");
$('#pay'+i).attr("disabled",'disabled');
}
}
}
function selectAll(a){
if(a.checked==true){
for(i=3;i<=5;i++){
$('#pay'+i).attr("checked","checked");
}
}else{
for(i=3;i<=5;i++){
$('#pay'+i).removeAttr("checked","checked");
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type='checkbox' id='pay1' onclick="showdis(this)">Remove Disabled
<input type='checkbox' id='pay2' disabled onclick="selectAll(this)">Checked 3,4,5
<input type='checkbox' id='pay3' disabled>3
<input type='checkbox' id='pay4' disabled>4
<input type='checkbox' id='pay5' disabled>5
Everything is working fine but when i unchecked the first checkbox its removing checked attribute from every checkbox except the second checkbox
Aucun commentaire:
Enregistrer un commentaire