Check Box Issue

4 posts, 0 answers
  1. : Arumuga Vignesh
    : Arumuga Vignesh  avatar
    21 posts
    Member since:
    Jul 2013

    Posted 30 Jul 2013 Link to this post

    Hi,

    I have six checkboxes inside telerik combobox control .  On  checking the first checkbox, I have to disable second and third one.

    Similarly, on checking fifth checkbox I have to disable sixth one. I tried using  onitemchecked,autopostback =true  and onclientitemchecked  events but couldn’t get the result.

    Please help with the sample code

    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 30 Jul 2013 Link to this post

    Hi Arumuga,

    Please have a look into the sample code I tried which works fine at my end.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true" OnClientItemChecked="OnClientItemChecked">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="Item 1" />
            <telerik:RadComboBoxItem runat="server" Text="Item 2" />
            <telerik:RadComboBoxItem runat="server" Text="Item 3" />
            <telerik:RadComboBoxItem runat="server" Text="Item 4" />
            <telerik:RadComboBoxItem runat="server" Text="Item 5" />
            <telerik:RadComboBoxItem runat="server" Text="Item 6" />
        </Items>
    </telerik:RadComboBox>

    JavaScript:
    <script type="text/javascript">
        function OnClientItemChecked(sender, args) {
            //accessing the clicked item.
            var item = args.get_item();
            if (item.get_index() == 0) {
                //Checking whether its the first item, then index will be zero.
                if (item.get_checked()) {
                    //Disabling the second and third item.
                    sender.get_items().getItem(1).set_enabled(false);
                    sender.get_items().getItem(2).set_enabled(false);
                }
                else {
                    sender.get_items().getItem(1).set_enabled(true);
                    sender.get_items().getItem(2).set_enabled(true);
                }
            }
            else if (item.get_index() == 4) {
                if (item.get_checked()) {
                    sender.get_items().getItem(5).set_enabled(false);
                }
                else {
                    sender.get_items().getItem(5).set_enabled(true);
                }
            }
        }
    </script>

    Thanks,
    Shinu.
  3. : Arumuga Vignesh
    : Arumuga Vignesh  avatar
    21 posts
    Member since:
    Jul 2013

    Posted 08 Aug 2013 Link to this post

    Hi,
    I have a combo box with checkboxes. OnClientItemChecked and OnClientDropDownClosed I have written a javascript like below.

     

    function OnClientItemChecked(sender, eventArgs)

    {    

        var comboBox = $find("<%=rbcmbDemoStatus.ClientID %>");

        var item = eventArgs.get_item();

        

        if(comboBox.get_items().getItem(0).get_checked())

        {                  

        sender.get_items().getItem(1).set_enabled(false);

        sender.get_items().getItem(2).set_enabled(false);

        }    

        else if(comboBox.get_items().getItem(1).get_checked())

        {    

        sender.get_items().getItem(0).set_enabled(false);

        sender.get_items().getItem(2).set_enabled(false);

        }        

    }

     

    It worked fine when I called this javascript from aspx itself. But when I moved the javascript to separate script.js file,

    It is throwing error like sender undefined.

     

    This is calling event:

     

    <telerik:RadComboBox ID="rbcmbDemoStatus" runat="server" CheckBoxes="true" Width="160" OnClientItemChecked="OnClientItemChecked" OnClientDropDownClosed="OnClientDropDownClosed" Skin="Office2007">

    I called the script like this:

     

    <script type="text/javascript" src="~/Scripts/JCO Scripts.js"></script>

    <script language ="javascript" type ="text/javascript">

    OnClientItemChecked(sender, eventArgs)

    </script>

  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Aug 2013 Link to this post

    Hi Arumuga,

    Please try with the following code in your external JS.

    JavaScript:
    function OnClientItemChecked(sender, eventArgs) {
        var item = eventArgs.get_item();
        if (sender.get_items().getItem(0).get_checked()) {
            sender.get_items().getItem(1).set_enabled(false);
            sender.get_items().getItem(2).set_enabled(false);
        }
        else if (sender.get_items().getItem(1).get_checked()) {
            sender.get_items().getItem(0).set_enabled(false);
            sender.get_items().getItem(2).set_enabled(false);
        }
    }
     
    Also please have a look at this forum thread which deals with a similar scenario.

    Thanks,
    Shinu.
Back to Top