Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  176] [ 7]  / answers: 1 / hits: 28977  / 9 Years ago, wed, march 18, 2015, 12:00:00

I want to uncheck all checkboxex inside the 'test' div without those checkboxes whose attributes are disabled.



<div id=test>
<input type=checkbox id=check1 name=check1>
<input type=checkbox id=check01 name=check01 disabled=disabled>
<input type=checkbox id=check2 name=check2 disabled=disabled>
<input type=checkbox id=check3 name=check3>
<input type=checkbox id=check4 name=check4>
<input type=checkbox id=check50 name=check50>
<input type=checkbox id=check6 name=check6>
</div>
<input type=button id=uncheckAll onclick=uncheckAll('test')>
<script language=javascript>
function uncheckAll() {
$('#' + divid + ' :checkbox').attr('checked', false);
/*
This function uncheck all of the checkboxes, which i don't want, i want to
uncheck only checkboxes whose attributes are not disabled.
/*
}*/
</script>

More From » jquery

 Answers
4

You need to accept the param named divId then use :enabled filter to filter out disabled checkboxes



function uncheckAll(divid) {
$('#' + divid + ' :checkbox:enabled').prop('checked', false);
}


Demo: Fiddle






If no jQuery



function uncheckAll(divid) {
var checks = document.querySelectorAll('#' + divid + ' input[type=checkbox]');
for(var i =0; i< checks.length;i++){
var check = checks[i];
if(!check.disabled){
check.checked = false;
}
}
}


Demo: Fiddle


[#67396] Monday, March 16, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harrisa

Total Points: 514
Total Questions: 93
Total Answers: 93

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
;