How do I get back on onChange all selected values in my multiselect dropdown. Used plugin here. Trying to use the following but I think I\'m on the wrong track
$
In my case i was using jQuery validation rules with
submitHandler
function and submitting the data as new FormData(form);
Select Option
<select class="selectpicker" id="branch" name="branch" multiple="multiple" title="Of Branch" data-size="6" required>
<option disabled>Multiple Branch Select</option>
<option value="Computer">Computer</option>
<option value="Civil">Civil</option>
<option value="EXTC">EXTC</option>
<option value="ETRX">ETRX</option>
<option value="Mechinical">Mechinical</option>
</select>
<input type="hidden" name="new_branch" id="new_branch">
Get the multiple selected value and set to new_branch
input value & while submitting the form get value from new_branch
Just replace hidden
with text
to view on the output
<input type="text" name="new_branch" id="new_branch">
Script (jQuery / Ajax)
<script>
$(document).ready(function() {
$('#branch').on('change', function(){
var selected = $(this).find("option:selected"); //get current selected value
var arrSelected = []; //Array to store your multiple value in stack
selected.each(function(){
arrSelected.push($(this).val()); //Stack the value
});
$('#new_branch').val(arrSelected); //It will set the multiple selected value to input new_branch
});
});
</script>