I want to remove all the options except only one in the select box and trigger the onchange based on this last option. I see the trigger calls infinite times. Below is my codes:
<select id="payment-method-pmid" name="payment_method[pmid]" class="form-select required ajax-processed">
<option value="select">- Select -</option>
<option value="1">Collect on delivery</option>
<option value="3">PayPal Instant Payment Notification</option>
</select>
(function ($) {
Drupal.behaviors.siteModule = {
attach: function (context, settings) {
$('#payment-method-pmid').find('option').not(':last').remove();
$('#payment-method-pmid').val(3).trigger('change');
}
};
})(jQuery);
I've re-written my codes as below and it done.