Get Selected Value of ComboBox in Javascript

4 posts, 0 answers
  1. Kevin
    Kevin avatar
    265 posts
    Member since:
    Jun 2011

    Posted 11 Feb 2014 Link to this post

    I have figured out the long way to get the Dropdown Selected value of the combobox, but is there a shorter way than all this code

    So my current method is as follows
    var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>');
    var sCounty = SoldCounty.get_value();
               
    Then i can do something with the value.

    However why does this not work

    var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_value();
     
    Or this
     
    var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_SelectedValue();























  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Feb 2014 in reply to Kevin Link to this post

    Hi Kevin,

    Please try the following code snippet to get the SelectedItem value of RadComboBox.

    ASPX:
    <telerik:RadComboBox ID="ddlSoldCounty" runat="server" OnClientDropDownClosing="OnClientDropDownClosing1">
        <Items>
            <telerik:RadComboBoxItem Text="Invoice" runat="server" Value="10" />
            <telerik:RadComboBoxItem Text="Quote" runat="server" Value="5" />
        </Items>
    </telerik:RadComboBox>

    JavaScript:
    <script type="text/javascript">
        function OnClientDropDownClosing1(sender, args) {
            var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_selectedItem().get_value();
            //or
            var SoldCounty = $find('<%= ddlSoldCounty.ClientID %>').get_value();
            alert(SoldCounty);
        }
    </script>

    Please provide your full code if it doesn't help.
    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Frank
    Frank avatar
    86 posts
    Member since:
    Mar 2012

    Posted 21 May 2015 in reply to Princy Link to this post

    I have tried this syntax but I keep getting an System.Web.HttpUnhandledException.

    this line

    var cik = $find('<%= myCik.ClientID %>').get_selectedItem().get_value();

    always causes an the error.  anytime I have '<%=  %>' inside my javascript I get the System.Web.HttpUnhandledException.

  5. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 26 May 2015 Link to this post

    Hi Frank,

    Using this syntax you are getting a reference to the client-side objects.The $find('<%= myCik.ClientID %>') may fail in the occasion when the control is not yet initialized. All ASP.NET Ajax controls are initialized when the page is fully loaded.

    If you need further assistance, please send us a runnable example which we can inspect locally and provide you with a solution.

    Regards,
    Aneliya Petkova
    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
Back to Top