Populate 2 dropdowns from change event

Hello
I have a dropdown that displays departments. I select a department and this triggers a change event which should populate 2 dropdowns with firstly #address details and the #box_rtv dropdown with boxes in that department.

What i happening is that the #box_rtv dropdown is not getting populated with any items. In firebug I can see that all data is being returned from php backend but just not populating the dropdown. The address dropdown is populating ok.

I am obviously coding something incorrectly and woud be grateful if someone could point out my error. I haven’t posted the php because it is being returned correctly on each change event. If however you need to see it, I shall be happy to post it. Many thanks

$(function() {
  $(document).on('change', '.rtvdept', function() {
    value = $(this).val();
    $(this).after('<div id="loader"><img src="/domain/admin/images/loader.gif" alt="loading files" /></div>');
    $.get('/domain/admin/requests/boxes/retrieve/loadboxRtvaddr.php?rtvaddr=' + value, function(data) {
      $("#address").html(data);
      $('#loader').slideUp(200, function() {
        $(this).remove();
        //console.log(data);
       //$("#address").val('');
        $("#address").attr("data-placeholder", "Select your new address");
        $("#address").trigger("chosen:updated");
      });
    }),
    $(this).after('<div id="loader"><img src="/domain/admin/images/loader.gif" alt="loading files" /></div>');
    $.get('domain/admin/requests/boxes/retrieve/loadboxRtvbox.php?rtvbox=' + value, function(data) {
      $("#box_rtv").html(data);
      $('#loader').slideUp(200, function() {
        $(this).remove();
        //console.log(data);
        //$("#box_rtv").val('');
        $("#box_rtv").attr("data-placeholder", "Select your new boxes");
        $("#box_rtv").trigger("chosen:updated");
      });
    });
  });
});

Do you have a working version of the code somewhere that people can look at? What form of data is being returned? What is #box_rtv?

Sorry for delay. I have decided to go another wy with this. Thanks for all your help. Have good day.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.