<div class="col-sm-10">
<div class="form-group field-input6">
<input type="hidden" name="ProductForm[suppliers]" value=""><select id="input6" class="form-control chosen-select js__products__suppliers" name="ProductForm[suppliers][]" multiple="multiple" size="4" data-placeholder="Choose..." style="display: none;">
<option value="15">test201</option>
<option value="27">test1012</option>
<option value="28">test1016</option>
</select><div class="chosen-container chosen-container-multi" title="" id="input6_chosen" style="width: 100%;"><ul class="chosen-choices">
<li class="search-field">
<input class="chosen-search-input default" type="text" autocomplete="off" value="Choose..." style="width: 100.938px;">
</li>
</ul>
<div class="chosen-drop">
<ul class="chosen-results"></ul>
</div></div>
<div class="help-block"></div>
</div>
</div>
$('select').change(function() {
console.log($(':selected', this).text());
});
это же мультиселект, и когда выбрано два элемента, то имена двух элементов и получаем, а мне нужно только тот который выбрали
$('select').on('click', 'option', function(e) {
const $target = $(e.target);
if ($target.is(':selected')) {
console.log($target.text());
}
});
let prevSelected = [];
$('select').on('change', function(e) {
const selected = $(':selected', this).get().map(n => n.innerText);
const newSelected = selected.find(n => !prevSelected.includes(n));
prevSelected = selected;
if (newSelected) {
console.log(newSelected);
}
});