I want to select several options with the help of jquery. and take the value of the selected options and write it in the paragraph. My problem is that it only takes the first option and does not take the next selected option and only returns the value obtained first. I have to write it in
until there are no other options. and I need to delete the selected options
$(document).ready(function() {
var max_fields = 26;
var wrapper = $(".container1");
var add_button = $(".add_form_field");
var selectopion = $("#id_100 option:selected").val();
var x = 1;
$(add_button).click(function(e) {
$("#id_100 option:selected").remove();
e.preventDefault();
if (x < max_fields) {
var numbers = x++;
//add input box
$(wrapper).append('<div><p>ID: ' + selectopion + ' student</p></div>');
} else {
alert('The maximum number of students has been added');
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<label for="day">Students</label>
<select name="students_info" class="form-control" id="id_100">
<option value="6">6 || student</option>
<option value="5">5 || student</option>
<option value="4">4 || student</option>
<option value="3">3 || student</option>
<option value="2">2 || student</option>
<option value="1">1 || student</option>
</select>
<input type="submit" name="button" id="submit_button"
class="btn btn-success add_form_field" value="Add">
<div class="container1 form-group"></div>