One solution is to use the methods Array.from()
and map
for all selected values.
var values=Array.from($(".Categoria").find(':selected')).map(function(item){
return $(item).text();
});
Working solution
$('select').selectpicker();
$(".Categoria").change(function() {
f2();
});
var f2 = function(){
var values=Array.from($(".Categoria").find(':selected')).map(function(item){
return $(item).text();
});
$('.ChangeCategory').val(values);
}
f2();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/css/bootstrap-select.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/js/bootstrap-select.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/><select class="selectpicker Categoria" multiple="">
<option selected>A1</option>
<option selected>A2</option>
<option>A3</option>
<option>A4</option>
</select>
<input type="text" class="ChangeCategory" name="ChangeCategory">
Run codeHide result, arrow
.
$('.ChangeCategory').val(Array.from($( ".Categoria option:selected" )).map(a=>$(a).text()).join(','));