Getting an Instance

2 posts, 0 answers
  1. Lukus
    Lukus avatar
    13 posts
    Member since:
    Nov 2010

    Posted 20 Apr 2011 Link to this post

    Hello,

    I am having trouble getting an instance of my radcombobox in my javascript code.  It just returns an "Object."

    function OnCheck_Changed(cb) {
            var add1   =  $get("<%= txt_Address.ClientID    %>");
            var add2   =  $get("<%= txt_Address2.ClientID   %>");
            var city   =  $get("<%= txt_City.ClientID       %>");
            var zip    =  $get("<%= txt_PostalCode.ClientID %>");
            var state  = $find("<%= cb_State.ClientID       %>");
            var hadd1  =  $get("<%= hdf_Address.ClientID    %>");
            var hadd2  =  $get("<%= hdf_Address2.ClientID   %>");
            var hcity  =  $get("<%= hdf_City.ClientID       %>");
            var hstate =  $get("<%= hdf_State.ClientID      %>");
            var hzip   =  $get("<%= hdf_PostalCode.ClientID %>");
     
            if (cb.checked == true) {
                //alert(hadd1);
                add1.value = hadd1.value;
                add2.value = hadd2.value;
                city.value = hcity.value;
                zip.value = hzip.value;
                //var select = state.findItemByValue(hcity.value);
                //select.select();
                add1.readOnly = true;
                add2.readOnly = true;
                city.readOnly = true;
                zip.readOnly = true;
                //state.Disable();
            }
            else {
                //alert(state);
                add1.readOnly = false;
                add2.readOnly = false;
                city.readOnly = false;
                zip.readOnly = false;
                //state.Enabled = true;
            }
        }

    This is the radcombobox I am trying to get:
    <telerik:RadComboBox ID="cb_State" runat="server" DataSourceID="eds_States" HighlightTemplatedItems="true"
                            AutoPostBack="false" Skin="Simple" DropDownWidth="195" EnableLoadOnDemand="True"
                            Width="75px" DataValueField="STATE_CODE" DataTextField="STATE_CODE" OnDataBound="cb_State_DataBound" Enabled="false">
                            <HeaderTemplate>
                                <table>
                                    <tr>
                                        <td style="width: 45px">
                                            State Code
                                        </td>
                                        <td style="width: 150px">
                                            State Name
                                        </td>
                                    </tr>
                                </table>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <table>
                                    <tr>
                                        <td style="width: 45px">
                                            <%# DataBinder.Eval(Container.DataItem, "STATE_CODE")%>
                                        </td>
                                        <td style="width: 150px">
                                            <%# DataBinder.Eval(Container.DataItem, "STATE")%>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </telerik:RadComboBox>

    I have gone over it many times and can't seem to find what I am missing. Please help.
    Thanks
  2. Dean
    Dean avatar
    43 posts
    Member since:
    Jun 2009

    Posted 20 Apr 2011 Link to this post

    Hi Lukus,

    From what I've tested in a demo application I see only had a problem selected the item in the combobox is the combobox is disabled. I created some code that imitates what you are trying to do and had no problems with the combobox item. See my code below.

    If you do an Alert(state); it will show [object Object]

    Javascript
    <script type="text/javascript" language="javascript">
        function OnCheck_Changed(cb) {
            var state = $find("<%= cb_State.ClientID %>");
            if (cb == true) {
                state.enable();
                var item = state.findItemByValue('Item 2');
                if (item) {
                    item.select();
                }
                state.disable();
            }
            else {
                state.enable();
            }
        }
    </script>

    ASP Markup
    <asp:CheckBox ID="chkEnableDisableState" runat="server" onclick="OnCheck_Changed(this.checked);" />
    <br />
    <telerik:RadComboBox ID="cb_State" runat="server" Enabled="false">
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="Item 1" Value="Item 1" />
            <telerik:RadComboBoxItem runat="server" Text="Item 2" Value="Item 2" />
            <telerik:RadComboBoxItem runat="server" Text="Item 3" Value="Item 3" />
        </Items>
    </telerik:RadComboBox>


    Another way you could do the javascript is like this.

    <script type="text/javascript" language="javascript">
        function OnCheck_Changed(cb) {
            var state = $telerik.toComboBox($find("<%= cb_State.ClientID %>"));
            if (cb == true) {
                state.enable();
                var item = state.findItemByValue('Item 2');
                if (item) {
                    item.select();
                }
                state.disable();
            }
            else {
                state.enable();
            }
        }
    </script>

    Hope this helps.
Back to Top