This is suppose to be a very simple question, but I can't seem to figure it out.
I have forms over data type scenario, where someone can enter information about the services offered. So the form looks like this
- [DropDown: serviceType] [DropDown: services] [TextBox: info]
- [DropDown: serviceType] [DropDown: services] [TextBox: info] ... 5 [DropDown: serviceType] [DropDown: services] [TextBox: info]
I want the corresponding service list populated based on the selection Service Type list, so I have the following code:
$(document).ready(function() {
$("select#serviceType").change(function() {
var serviceId = $("#serviceType > option:selected").attr("value");
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "GetServicesByServiceType/" + serviceId,
data: "{}",
dataType: "json",
success: function(data) {
var options = '';
for (index in data) {
var service = data[index];
options += "<option value='" + service.ServiceId + "'>" + service.Name + "</option>";
}
$("#services").removeAttr('disabled').html(options);
}
}
);
});
});
I am having the following problems:
- I am referencing a specific element ID, instead I would want that to be figured out programatically, since number of elements varies.
- I want the services drop down to refresh on select change as well as well initially on load
Any help would be greatly appreciated!