Upon running the following code:
<div id="1-round" class="btn-group btn-group-toggle btn-lg" data-toggle="buttons" >
{% for checkbox in form.players_choice %}
<label class="btn btn-primary rounded mr-3 active btn-lg 1-round" style="margin-bottom:8px;">
<script>
$('label').click(function() {
$(this).addClass('btn-primary').removeClass('btn-default').siblings().removeClass('btn-primary').addClass('btn-default');
if ($('#id_players_choice_0').is(':checked')) {
x = id_players_choice_0.value};
if ($('#id_players_choice_1').is(':checked')) {
x = id_players_choice_1.value};
alert(x);
});
</script>
{{checkbox}}
</label>
{% endfor %}
</div>
Upon use, the value (the x variable) is only retrieved on the second or third button press.
Is there a solution for this issue?
Thank you!