This is a migrated thread and some comments may be shown as answers.

client side setting checkbox on client side

5 Answers 499 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 23 May 2012, 04:30 PM
How do I check or uncheck a checkbox in the RadComboBox when it's checkbox is allowed?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 May 2012, 05:17 AM
Hi Craig,

Try the following javascript to check or uncheck a checkbox in a RadComboBox.

JS:
<script type="text/javascript" >
 function OnClientClick()
  {
        var combo = $find("<%=RadComboBox1.ClientID %>");
        if (combo.get_items().getItem(0).get_checked())
        {
            combo.get_items().getItem(0).set_checked(false);
        }
        else
        {
            combo.get_items().getItem(0).set_checked(true);
        }
  }
</script>

Hope this helps.

Thanks,
Princy.
0
Craig
Top achievements
Rank 1
answered on 24 May 2012, 03:22 PM
This is very helpful thank you. Since I can't get the telerik intellisense to work it is hard to apply this where I want to. A little background will help. I have a class that generates a list of items that I want to display in a radcombobox. I can get the list to display and by enabling the checkbox feature of the combobox the user will be able select one of more items from the combobox. The problem i am trying to solve is how to make sure the first item "All" is unchecked when a user checks an item that is not "All". But also if the user does check "All" then I want to uncheck all of the other items. Since I am not familiar with the clientside API and intellisense for the telerik components is not working for clientside code I am not able to work this out on my own. Is there written documentation explaining the whole clientside API? What I have been able to find is not extensive enough.


Craig
0
Princy
Top achievements
Rank 2
answered on 25 May 2012, 06:41 AM
Hi Craig,

Here is the sample code which I tried based on your scenario. You can use debugger in IE for javascript intellisense.

JavaScript:
<script type="text/javascript">
 function OnClientItemChecking(sender, eventArgs)
  {
        if (eventArgs._item._properties._data.value == "all")
        {
            for (var i = 1; i < sender.get_items().get_count(); i++)
             {
                sender.get_items().getItem(i).set_checked(false);
             }
        }
        else if (sender.get_items().getItem(0).get_checked())
        {
            eventArgs.set_cancel(true);
        }
  }
</script>

Thanks,
Princy.
0
SUBBU
Top achievements
Rank 1
answered on 11 Feb 2016, 05:06 AM

In my case, set_checked(true) alone didn't work,

    combo.get_items().getItem(0).set_checked(true);

    $(combo.get_items().getItem(0)._element).find('input').prop('checked', true);

 

This worked for me!!!

0
Nencho
Telerik team
answered on 15 Feb 2016, 09:37 AM
Hello Subramanian,

The demonstrated usage should properly work as it is a part of the Client API of the control.
combo.get_items().getItem(0).set_checked(true);
Here you can find the entire ClientAPI of the control listed with explanations and some examples:
http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/client-side-programming/objects/radcomboboxitem-object

In the attachment you can find a simple example, demonstrating the proper behavior of the above implementation.

The reason why it may not work at your end is if there is any javascript error on the page. Please make sure that this is not the case.

Regards,
Nencho
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Craig
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Craig
Top achievements
Rank 1
SUBBU
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or