tags:

views:

39

answers:

1
function checkAll(custId){
        var id;
        if(document.getElementById(custId).checked == true){
        <%for (CustomerGroup custGroup : customerGroupList) {%>

            if(custId==<%=custGroup.getCustomerGroupId()%>){
                <%List<Account> list = accountDelegate
                    .findAccountEntityByGroupId(custGroup
                            .getCustomerGroupId());
            for (Account account : list) {%>
                        id=<%=account.getAccountId()%>
                        document.getElementById(id).checked=true;
                <%}%>
            }
    <%}%>
    }else {
        <%for (CustomerGroup custGroup : customerGroupList) {%>

            if(custId==<%=custGroup.getCustomerGroupId()%>){
            <%List<Account> list2 = accountDelegate
                    .findAccountEntityByGroupId(custGroup
                            .getCustomerGroupId());
            for (Account account : list2) {%>
                        id=<%=account.getAccountId()%>
                        document.getElementById(id).checked=false;
            <%}%>
    }
    <%}%>
}
}

Here I have passed custId as a id of checkbox.Problem here is if(document.getElementById(custId).checked == true

each time this condition will evaluate to false and thus control goes on else part. so how can i know wether checkbox is cheched or not ?.

+1  A: 

The checked property is what you need to use to verify if a checkbox is checked:

<html>
<head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript">
    window.onload = function() {
        if (document.getElementById('test').checked) {
            alert('the checkbox is checked');
        }
    };  
    </script>
</head>
<body>

<input id="test" name="test" type="checkbox" checked="checked" />

</body>
</html>
Darin Dimitrov