1

I am using $.publish to populate the dropdown (Struts 2 select tag) after that, I want the dropdown to be auto-selected to a value.

I tried the following:

$.publish("reloadAttributeList");
        //$('#selectedAttribute option[value="attributeId"]');
        $('#selectedAttribute').val(attributeId).change();
        //$('#selectedAttribute').val(attributeId);

None worked.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Preethi Jha
  • 167
  • 13

1 Answers1

0

No, after using $.publish() you can't auto select the drop down. The code to auto select dropdown should be inside the $.subscribe(). Some another event you should publish when loading is complete.

<script>
  $.subscribe('loadCompleteAttributeList', function(event, data) {
    $('#selectedAttribute').val(attributeId);
  });
</script>
Roman C
  • 49,761
  • 33
  • 66
  • 176