I have a RadComboBox and I am attempting to retrieve the selected item in JavaScript. Using .NET 4.0. in FireFox 11.0.
The RadComboBox is as follows:
<telerik:RadComboBox ID="ddlBillingState" runat="server" AppendDataBoundItems="True" DataTextField="Name" DataValueField="StateProvinceID" ondatabinding="ddlBillingState_DataBinding" ondatabound="ddlBillingState_DataBound"> <Items> <telerik:RadComboBoxItem Text="Select a State" /> </Items> </telerik:RadComboBox>
The above RadComboBox resides inside a FormView ID=VendorFormView.
When I use the following code the JavaScript terminates before the second alert is issued. The statement with the get_selectedItem call seems to be failing. The following JavaScript is contained with the Header section of the page in which the RadComboBox resides. This JavaScript runs when the user clicks a CheckBox on the page. The ddlBillingState control does have a selected item, which was selected by the user, but when I attempt to retrieve the selected item the JavaScript terminates.
Any help would be greatly appreciated.
var ddlBillingState = document.getElementById('<%=VendorFormView.FindControl("ddlBillingState").ClientID%>'); var ddlShippingState = document.getElementById('<%=VendorFormView.FindControl("ddlShippingState").ClientID%>'); if (ddlBillingState != null && ddlShippingState != null) { alert("Assigning selected billing state"); var selectedBillingItem = ddlBillingState.get_selectedItem(); alert("selectedBillingItem assigned"); var shippingItem = ddlShippingState.findItemByText(selectedBillingItem.get_text()); alert("Shipping Item assigned"); shippingItem.select(); alert("Done"); }