Using jQuery to get RadDropDownList value

12 posts, 0 answers
  1. Ramandeep
    Ramandeep avatar
    2 posts
    Member since:
    Aug 2013

    Posted 14 Aug 2013 Link to this post

    I am trying to get the value of selected item from a RadDropDownList using the below code snippet:
    ddlEntType= '<%= rddlEnterprise.ClientID %>

    but it is giving me "undefined" as the result.

    Can you please provide the solution for this?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2013 Link to this post

    Hi Ramandeep,

    Please have a look at the following code I tried to alert the RadDropDownList selected value.

    JavaScript:
    <script type="text/javascript">
        function getdropdownlistSelectedItem(sender, args) {
            var raddropdownlist = $find('<%=RadDropDownList1.ClientID %>');
            var selecteditem = raddropdownlist.get_selectedItem().get_value();
            alert(selecteditem);
        }
    </script>

    Thanks,
    Princy.
  3. Ramandeep
    Ramandeep avatar
    2 posts
    Member since:
    Aug 2013

    Posted 14 Aug 2013 Link to this post

    I tried working out with the solution but i am still getting "undefined" result. 
  4. Kurt Kluth
    Kurt Kluth avatar
    171 posts
    Member since:
    Oct 2009

    Posted 28 Aug 2014 in reply to Ramandeep Link to this post

    Was there ever a solution to this problem?

    I am experiencing the same problem that I get "undefined".

        function getdropdownlistSelectedItem(sender, args) {
            var valueFind = $find("<%=Restaurants.ClientID%>").get_selectedItem().get_value();
            alert(valueFind);
        }
     
    <telerik:RadDropDownList ID="Restaurants" name="placetype" runat="server" DefaultMessage="Select Restaurant" OnClientItemSelected="getdropdownlistSelectedItem">
           <Items>
                 <telerik:DropDownListItem runat="server" Text="All Restaurants" Value="Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="American" Value="American Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="Asian" Value="Asian Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="French" Value="French Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="German" Value="German Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="Indian" Value="Indian Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="Italian" Value="Italian Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="Mediterranean" Value="Mediterranean Restaurants"></telerik:DropDownListItem>
                 <telerik:DropDownListItem runat="server" Text="Mexican" Value="Mexican Restaurants"></telerik:DropDownListItem>
            </Items>
    </telerik:RadDropDownList>
       

     

     

     

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

    Posted 29 Aug 2014 in reply to Kurt Kluth Link to this post

    Hi Kurt Kluth,

    Please try the below JavaScript to achieve your  scenario.

    JavaScript:
    function getdropdownlistSelectedItem(sender, args) {
        var count, length = sender.get_items().get_count();
        for (count = 0; count < length; count++) {
            if (sender.get_items()._array[count].get_selected()) {
                alert(sender.get_items()._array[count].get_value());
            }
        }
    }

    Thanks ,
    Princy.
  6. Kurt Kluth
    Kurt Kluth avatar
    171 posts
    Member since:
    Oct 2009

    Posted 29 Aug 2014 in reply to Princy Link to this post

    Princy,

    Thank you.  It worked like a charm. 

  7. bhargavi
    bhargavi avatar
    5 posts
    Member since:
    Apr 2015

    Posted 05 Jun 2015 in reply to Princy Link to this post

    how to validate rad dropdownlist to take value on clientclick asp:net button
  8. Ivan Danchev
    Admin
    Ivan Danchev avatar
    2150 posts

    Posted 05 Jun 2015 Link to this post

    Hello,

    The code snippet below demonstrates how you can validate a RadDropDownList on the client:
    <telerik:RadDropDownList ID="RadDropDownList1" runat="server">
        <Items>
            <telerik:DropDownListItem Text="" />
            <telerik:DropDownListItem Text="Tokyo" />
            <telerik:DropDownListItem Text="Osaka" />
            <telerik:DropDownListItem Text="Yokohama" />
            <telerik:DropDownListItem Text="Kyoto" />
        </Items>
    </telerik:RadDropDownList>
     
    <asp:Button ID="Button1" OnClientClick="return ValidateDropDownList();"
        runat="server" Text="Validate" />
     
    <script type="text/javascript">
     
        function ValidateDropDownList() {
     
            var isSelected = false;
            var dropDown = $find("<%= RadDropDownList1.ClientID %>");
            var selectedText = dropDown.get_selectedItem().get_text();
            if (selectedText != "") {
                isSelected = true;
            }
            else {
                alert("Select a city!");
            }
            return isSelected;
        }
    </script>

    Regards,
    Ivan Danchev
    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
  9. bhargavi
    bhargavi avatar
    5 posts
    Member since:
    Apr 2015

    Posted 05 Jun 2015 in reply to Ivan Danchev Link to this post

    i am unable to access raddatepicker in external js file.please help
  10. Santiago
    Santiago avatar
    1 posts
    Member since:
    Oct 2017

    Posted 18 Dec 2017 Link to this post

    I think you need to use .control. 

    At least that worked for me. This is an example not using JQuery, using GelElementByID (and Im almost sure the JQuery function is a shortcut to GetElementById) 

     

    var dropBox = document.getElementById("<%=ddlDescription.ClientID %>");
    alert(dropBox.control.get_selectedItem().get_value());

     

    Hope this helps

     

  11. Damian
    Damian avatar
    6 posts
    Member since:
    Mar 2011

    Posted 04 Aug 2018 Link to this post

    Has anyone running into a scenario where the suggested solutions work well except in an iOS device?

    mine keeps return the default value.

  12. Tsvetomir
    Admin
    Tsvetomir avatar
    790 posts

    Posted 08 Aug 2018 Link to this post

    Hi Damian,

    I would suggest that you use the findControl() method in order to access the Telerik controls client-side. Another approach would be to use client-side event handlers of the Telerik controls to get a reference to their objects. 

    For further reference you can have a look at the Access Telerik Controls on Client-Side help article.

    Kind regards,
    Tsvetomir
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top