how to use jquery or javascript to get the selected VALUE from telerik radcombobox? val() not working

14,858

Its been a little while since I've dealt with Telerik controls, but what you're doing is bypassing the apis Telerik has made for you to use, and that strikes me as a very bad thing. The next release of Telerik Controls could easily break your code.

Look, it shouldn't be that hard to pass the client id from the listview. There's several methods I'd tackle but I'll let you figure that on your own for now. Once you DO have the ClientID for the control, follow the example on telerik's site:

http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx

Once you have that id do some

var combo = $find(someVarReferencingTheId); 

Now you have a reference to the combobox in its clientside form. Now find some function that gets what you want from here:

http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html

...

PROFIT!

EDIT: that first link to demos.telerik.com isn't really even needed, I just showed that because that's what I used to get that line of code (I could never remember if it's $get or $find I needed to use, unless I was doing a lot of Telerik clientside stuff at the time.).

EDIT 2: $get and $find are ASP.NET constructs, not Telerik's.

Share:
14,858
Sinaesthetic
Author by

Sinaesthetic

Updated on June 04, 2022

Comments

  • Sinaesthetic
    Sinaesthetic almost 2 years

    I have a listview that has a nested listview which contain radcomboboxes in the itemtemplate. As such, the IDs (as far as I know) are useless to me.

    For example, if I have 30 items, each one of those items is going to generate a new combobox so the names are going to be generated by asp. What I need is to be able to grab the selected value from whichever combobox is being worked by the user. I'm currently using jQuery and some absurd parent().parent().children() type nonsense in order to find the correct combobox in relation to the submit button.

    When submit button is clicked, I need it to find the selected value of the it's respective combobox so that I can send that to the post submission handler. The problem is that the .val() jQuery method is not working. When I use that with something like:

    $(this).parent().parent().children().children(".statusCbo").val();
    

    I end up getting the text value, not the selected value. I triple checked to make sure that I had the fields bound correctly in the aspx file;

    DataTextField = '<%#Eval("name") %>' DataValueField = '<%#Eval("id") %>'

    But as I said, I'm ending up with the DataTextField value of the selected item. The best explanation I could get was that it had something to do with how the control is requesting the content (via ajax).

    So at any rate, could anyone offer some suggestions on how to accurately get the selected value from the combobox?

    UPDATE: I was able to gain reference to the object through a different means:

    $(".submitTag").click(
            function () {
                var topLevel = $(this).closest(".CommentTopLevel");
                var status = topLevel.find(".StatusTag").get_value();                   
    
                //stub to test value
                alert(status);
                return false;
            });
    

    from here, if use status.val(), it will give me the text instead of the value (same issue as before). The documentation implies that I should use status.get_value(); but this is blowing up saying that the method is not supported from the object. Any ideas?

    UPDATE: nevermind, I found that it is a jquery object being returned, so the method isn't included. Continuing to dig.

    SOLUTION: There was just an extra step i needed to do to use traditional methods. I don't know what it took so long for it to click with me:

    $(".submitTag").click(
        function(){
            var topLevel = $(this).closest(".CommentTopLevelTag"); //gets the parent container
            var comboBoxID = topLevel.find(".StatusTag").attr("ID"); //gets the clientID of the jQuery object
            var comboBoxRef = $find(comboBoxID); //finds the control by id and brings back a non-jQuery object (useable)
            var comboBoxSelectedValue = comboBoxRef.get_value(); //uses the Telerik method to get the selected value
        });