populate telerik dropdown list using jquery

1 posts, 0 answers
  1. Sam
    Sam avatar
    1 posts
    Member since:
    Aug 2012

    Posted 22 Aug 2012 Link to this post

    I am having issues with populating a telerik dropdown list using jquery. I get the following Error:

    'get(...).options' is null or not an object

    On line:

    $("#courseID").get(0).options.length = 0;

    Here is my telerik dropdown list:

                    <%= Html.Telerik().DropDownList()
                   
    .Name("courseID")
                   
    .HtmlAttributes(new{ @id="courseID"})
                    %>

    Here is how I am trying to populate it using jquery:

    I call the populateDDL function on "StudentID" focusout event, here is the function.

    function populateDDL() {

    var link = '/Student/EnrollerCourse';
    $
    .ajax({
        type
    : 'POST',
        url
    : link,
        data
    : { id: $('#StudentId').val() },
        dataType
    : 'json',
        success
    : function (result) {
             $
    ("#courseID").get(0).options.length = 0;
            $
    ("#courseID").get(0).options[0] = new Option("Select", "Select");
            $
    .each(result.courseID, function (item, value) {
               
    var courseID = value;
                $
    ("#courseID").get(0).options[$("#courseID").get(0).options.length] = new Option(courseID);
           
    });          
       
    },
        error
    : function (result) {
            alert
    ("Failed")
       
    }
    });
    }
Back to Top