I have a dropdown list of companies. I also have some dropdown lists of contacts (primary_contact, sales_contact, insurance_contact) which all belong to class "contact". When the company changes, I update the list of available contacts using the following code:
$('#company').change(function () {
var company = $(this)[0].value.toString();
$.getJSON('<%= ResolveUrl("~/Subcontracts/CompanyContacts/") %>' + company, null, function (data) {
$('.contact').empty().append("<option value=''>**Select Contact**</option>");
$.each(data, function (index, optionData) {
$('.contact').append("<option value='" + optionData.contact_id + "'>" + optionData.contact_name + "</option>");
});
});
});
Some contacts are valid for multiple subsidiaries. If the previously selected contact shows up in the new contact list, I would like for them to still be selected. So, if the previously selected sales_contact is in the list, select them. Same for primary_contact and insurance_contact. How can I do this?