I have a multi select field using select2 in my form, i want to get all the value selected when submit, but when I print the value, its only get the value of the last selected option, how can i fix this?
Any help is much appreciated, below is my code :
html
<select class="js-example-basic-multiple" name="Project" multiple="multiple" style="display:inline-block;">
<option value="ALL" checked="1">ALL</option>
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
<option value="4">d</option>
</select>
<script>
$('.js-example-basic-multiple').select2();
$('.js-example-basic-multiple').on('change', function() {
var a = $('.js-example-basic-multiple').val();
})
</script>
view.py
if 'Project' in request.GET:
print(request.GET['Project'])
UPDATE: Thanks to @Blurp, I just change request.GET['Project']
to request.GET.getlist('Project')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With