Trigger change function and set the value of select in jquery?

Hi I am having given code

$('#filled-in-box2').on('click', function () {
    if ($('#filled-in-box2').is(':checked')) {
        $('select#employee_permanent_address_attributes_country').val($('select#employee_contact_attributes_country').val()).change();
      $('select#permanent_address_state_code').val($('select#contact_state_code').val());
    }
});

So I want after change function or when change function trigger at that time only permanent_address_state_code value will set same as contact_state_code value.
I have tried this code too but its not working

$('#filled-in-box2').on('click', function () {
    if ($('#filled-in-box2').is(':checked')) {
        $('select#employee_permanent_address_attributes_country').val($('select#employee_contact_attributes_country').val()).trigger('change',function(){
            $('select#permanent_address_state_code').val($('select#contact_state_code').val());
        });

    }
  });

Please guide me how to solve this. Thanks in advance.


Source: jquery

Leave a Reply