I'm trying to accomplish when an option is selected/unselected on a multiple select the onChange event will call a function to add or remove the dynamic field that is selected/unselected.
I've been trying for a few hours to think of the best logical approach to get this to work.
$('.multi-select').on('change', function() {
$.each($(this).val(), function() {
/* [ Some logic to check if a dynamic input should be removed or added. ]*/
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="multi-select" multiple>
<option value="0" selected>Col 0</option>
<option value="1">Col 2</option>
<option value="2" selected>Col 2</option>
...
</select>
<div class="dynamic-fields">
<input type="text" name="option[0]" value="asc">
<input type="text" name="option[2]" value="desc">
</div>
I just need some guidance with the best approach that I should take.