OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Django - Checkbox onchange event only work if I click the label

  • Thread starter Thread starter Nico44044
  • Start date Start date
N

Nico44044

Guest
On a Django template I have a checkbox named "test' from a Form

Forms.py

Code:
test = forms.MultipleChoiceField(required=False,widget=forms.widgets.CheckboxSelectMultiple(), label="test")

When I try to make something happend with the onchange event, it's only working if I'm clicking the label of the checkbox. If I check or uncheck the box nothing happens.

Template

Code:
$(function(){

   $('#id_test_0').on("change", function() {
    window.alert("change")})
  });

What am I missing here ?

Thanks

<p>On a Django template I have a checkbox named "test' from a Form</p>
<p>Forms.py</p>
<pre><code>test = forms.MultipleChoiceField(required=False,widget=forms.widgets.CheckboxSelectMultiple(), label="test")
</code></pre>
<p>When I try to make something happend with the <code>onchange</code> event, it's only working if I'm clicking the label of the checkbox.
If I check or uncheck the box nothing happens.</p>
<p>Template</p>
<pre><code>$(function(){

$('#id_test_0').on("change", function() {
window.alert("change")})
});
</code></pre>
<p>What am I missing here ?</p>
<p>Thanks</p>
 

Latest posts

I
Replies
0
Views
1
Isaac P. Liu
I
U
Replies
0
Views
1
user3658366
U
G
Replies
0
Views
1
Giampaolo Levorato
G
M
Replies
0
Views
1
Marcelo Rodrigo Nascimento
M
Top