フォームの selectservices_dd
で select2 プラグインを使用しています。ページに class のリンクがあります.js-autoselect
。これをクリックすると、そのリンク タグの ID を取得し、クリックしたボタンに応じて select2 オプションを変更します。
value 属性は、リンクの idの<option>
属性と一致します。以下のコードは値を正常に変更していますが、select2 は更新されておらず、まだ最初の選択が表示されています。
$('.js-autoselect').click(function(e){
e.preventDefault();
var option = $(e.target).attr('id').trim().toLowerCase(); // option =link1
$('#services_dd option:selected').val(option);
alert($('#services_dd option:selected').val()); // this alerts link1 which is correct
});
select2を更新する方法を知っている人はいますか