0

I have companies in the dropdown list that are active and deleted(deleted companies will show "(deleted)"), I want to have a checkbox to show/hide the deleted ones (client side).

$('#drAdvisor').change(function () { //select broker to get client
    var lic_id = $(this).val();
    getClientByBroker(lic_id)

function getClientByBroker(lic_id) {
    try {
        $.ajax({
            url: '../Admin/GetClientByBroker',
            type: "POST",
            contentType: 'application/json;',
            dataType: "json",
            data: JSON.stringify({ "Lic_ID": lic_id }),
            success: function (data) {
                $.each(data, function (key, value) {
                    $('#drCompany').append($("<option> 
</option>").val(value.CLIENTID).html(value.CLIENTNAME));
                });
                },
            });
        } catch (e) {console.log(e); }
}

enter image description here

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
  • 1
    how are the excluded companies identified? – Mateus Gonçalves Apr 17 '19 at 22:23
  • in database, there is an is_del column... model.SelectAllClientDetails = model.FilterAccountsDetails[0].Company.OrderBy(x => x.CLIENTNAME).ToList();.........return Json(model.SelectAllClientDetails, JsonRequestBehavior.AllowGet); – GTA0814 Apr 17 '19 at 22:27
  • 1
    Does this help? https://stackoverflow.com/questions/1271503/hide-options-in-a-select-list-using-jquery – Dan Apr 17 '19 at 22:59

1 Answers1

0

I do not know how your default data is in your is_del column, but try and replace it in the condition if necessary.

  $.each(data, function (key, value) {
      if(key.is_del != ''){ //change here if necessary, I do not know how it is
        $('#drCompany').append($("<option></option>").val(value.CLIENTID).html(value.CLIENTNAME + ' (Deleted)'));             
      }else{
        $('#drCompany').append($("<option></option>").val(value.CLIENTID).html(value.CLIENTNAME));
      }
  });