I have a checkbox ".invalidDropChk" and when I click on it I want its child checkboxes to get clicked. That part is working fine. I have a "All" checkbox too. I want to check it if the other checkbox in the page ".invalidOffensive" is checked too. But the problem is that it is entering in both if and else part in the end and my checkbox "All" gets checked. Here is the code :
$('.invalidDropChk').live('click',function(){
if($(this).is(':checked')){
$(this).next().find('input[type="checkbox"]').attr('checked',true);
$(this).attr('checked',true);
var rad1 = document.getElementById("invalidDropChk");
if(rad1 != null && rad1.attributes['checked'])
rad1.checked = true;
}
else
{
$(this).next().find('input[type="checkbox"]').attr('checked',false);
$(this).attr('checked',false);
var rad1 = document.getElementById("invalidDropChk");
if(rad1 != null && rad1.attributes['checked'])
rad1.checked = false;
}
if (($(this).is(':checked')) && ($('.invalidOffensive').is(':checked'))){
$('.check-all ').prop('checked',true);
}
else{
$('.check-all ').prop('checked',false);
}
});
The jsp page code is:
<ul class="invalidDrop">
<c:choose>
<c:when test="${invalidDropForm.invalidStreetAddress==true && invalidDropForm.invalidSubName==true && invalidDropForm.derogatoryNames==true && invalidDropForm.businessNames==true && invalidDropForm.offensiveNames==true}">
<li><input type="checkbox" class="check-all" checked /> All</li>
</c:when>
<c:otherwise>
<li><input type="checkbox" class="check-all" /> All</li>
</c:otherwise>
</c:choose>
<li>
<c:choose>
<c:when test="${invalidDropForm.invalidStreetAddress==true && invalidDropForm.invalidSubName==true}">
<input type="checkbox" class="check-inside invalidDropChk" id="invalidDropChk" checked /> Invalid Name/Address
</c:when>
<c:otherwise>
<input type="checkbox" class="check-inside invalidDropChk" id="invalidDropChk" /> Invalid Name/Address
</c:otherwise>
</c:choose>
<ul class="inneritem">
<li><sf:checkbox path="invalidStreetAddress"/> Invalid Street Address</li>
<li><sf:checkbox path="invalidSubName" /> Invalid Sub Name</li>
</ul>
</li>
<li>
<c:choose>
<c:when test="${invalidDropForm.derogatoryNames==true && invalidDropForm.businessNames==true && invalidDropForm.offensiveNames==true}">
<input type="checkbox" class="check-inside invalidOffensive" id="invalidOffensive" checked/> Offensive, Derogatory, Business Names
</c:when>
<c:otherwise>
<input type="checkbox" class="check-inside invalidOffensive" id="invalidOffensive"/> Offensive, Derogatory, Business Names
</c:otherwise>
</c:choose>
<ul class="inneritem">
<li><sf:checkbox path="derogatoryNames" /> Derogatory Names</li>
<li><sf:checkbox path="businessNames" /> Business Names</li>
<li><sf:checkbox path="offensiveNames" /> Offensive Names</li>
</ul>
</li>
</ul>