Set RadComboBox value from javascript

nav100 picture nav100 · Jul 12, 2012 · Viewed 20.8k times · Source

I have a RadCombobox in a user control and I am trying to set the value to null or 0 from Javascript. The following code doesn't work. But it's not showing any error also.

function OnClientSelectedIndexChanged(sender, eventArgs) {
    var item = eventArgs.get_item();
        var ddl = document.getElementById('ctl00_plh1_Test1_Dropdown2_RadComboBox1_DropDown');
        ddl.selectedIndex = 0;

}

<telerik:RadComboBox ID="Dropdown1" runat="server" 
                             NoWrap="true" Width="250" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
                            <CollapseAnimation Duration="200" Type="OutQuint" />
                        </telerik:RadComboBox>



<uc2:RadComboBox ID="Dropdown2" runat="server" DdlAutoWidth="true"></uc2:RadComboBox>

Answer

codingbiz picture codingbiz · Jul 12, 2012

Try this.

var mycombobox = $find("<%= MyUserControl.FindControl("RadComboBox1").ClientID %>");

or

var mycombobox = $find("<%= RadComboBox1").ClientID %>");

mycombobox.clearSelection();

You might need this

<rad:RadScriptBlock runat="server" ID="RadCodeBlock">
   <script type="text/javascript">

   </script>
</rad:RadScriptBlock>