Click here to Skip to main content
15,174,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

I have an asp checkboxlist with items bound from database. It has items in the following manner.

PO_1
PO_2
DNPR_1
DNPR_2
DNPR_3

When any checkbox with 'DNPR' is checked, all other checkboxes should be unchecked and disabled.

I have to implement it using javascript.

For that, I want to get the checked/unchecked state and the id of the checked/unchecked checkbox when clicking a checkbox in checkboxlist.

I tried using the onclick javascript event to achieve this. But checked=false in the onclick event evenif I checked a checkbox.

In which javascript event, I get the state of the checkbox I checked/unchecked.

Please help.

regards,
Regeesh Joseph
Posted
Comments
[no name] 25-Jul-12 9:26am
   
Why are you using a checkbox for this? This is what radio buttons were invented for...
Sergey Alexandrovich Kryukov 25-Jul-12 12:21pm
   
This is not the same behavior. OP needs to uncheck and disable all buttons when one is checked. It could be a combination of one check box and some radio buttons, but OP uses check box list, not individual checkable controls. Of course, most likely rethinking of the UI is required, instead of implementing this behavior. However, we cannot be sure. That's why OP should start with description of the data model for the data being edited with the UI.
--SA
Sunasara Imdadhusen 26-Jul-12 8:20am
   
Please provide snippet of code that you had tried. so we can guide you accordingly.

1 solution

in click event it will work....

C#
function myfn() {
            var dlist = document.getElementById("CheckBoxList1");
            var count = dlist.cells.length;
            for (var i = 0; i < count; i++) {
                var cId = "CheckBoxList1_" + i;
//cId is the dynamic id created for checkboxes in the list
                var cbox = document.getElementById(cId);
                if (cbox.checked == true) {
                    alert("ok");
                }
            }
        }



XML
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
            onclick="myfn()">
            <asp:ListItem>one</asp:ListItem>
            <asp:ListItem>two</asp:ListItem>
            <asp:ListItem>three</asp:ListItem>
            <asp:ListItem>four</asp:ListItem>
        </asp:CheckBoxList>


this is working for me..
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900