Issuing a selection option for pre-populated selection fields using jQuery

I have this part of jQuery to prevent the selection of dropdown options that are already selected in another field.

    var $coll = $( 'select[name$="service"]' ).on( 'change', function () {
        $coll.each(function () {
              var val = this.value;
              if ( val === 'original' ) return;
              $coll.not( this ).children( '[value="' + val + '"]' ).prop( 'disabled', true );
        });
    });

The problem is that this only works when starting the selection from scratch (empty form). When I have a form with fields with pre-selected parameters, the function only starts after the second attempt.

Do you know how I can change this to check also the completed fields?

+2
source share
1 answer

All I had to do was .trigger("change")after the document was ready, so the check starts before the first selection.

0

Source: https://habr.com/ru/post/1541062/


All Articles