This is a migrated thread and some comments may be shown as answers.

populate telerik dropdown list using jquery

0 Answers 182 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
sam
Top achievements
Rank 1
sam asked on 22 Aug 2012, 06:56 PM

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")
   
}
});
}

No answers yet. Maybe you can help?

Tags
DropDownList
Asked by
sam
Top achievements
Rank 1
Share this question
or