I am working on a dynamic dropdown list in a table for each row where I select a course in one select list and the classes associated with it are shown in the second dropdown list.
I was able to perform this using jQuery and ajax but the problem is this works only on the first row of the table and not on the rest of the table.
Below is the jQuery code I am using.
$(function () {
$("#table").each(function () {
$("#CourseName").change(function () {
alert("changed");
$.ajax({
type: 'Post',
url: '/RegisterStudents/GetClass',
dataType: 'json',
data: { id: $("#CourseName").val() },
success: function (data) {
var items = '';
$("#ClassName").empty;
$.each(data, function (i, row) {
items += '<option value="' + row.value + '">' + row.text + '</option>'
});
$("#ClassName").html(items);
}
})
})
});
});
I expect the jQuery script to work for all the dropdown list in every row of the table.