Skip to content
Advertisement

Checkbox listener not firing

I have set up a checkbox that should appear with each row in the list. I would like to pass row.id and boolean based on checkbox state. But the problem is that it only works for the first checkbox: id and boolean state is passed.

JavaScript

I have added javascript to listen to checkbox state and after checking, send a POST request to Flask app. It works but it only fires when the first checkbox is checked, all other checkboxes generated by Jinja2 are ignored.

JavaScript

Advertisement

Answer

  1. You only get the first when you use querySelector
  2. you have a dot in front of the input that should not be there
  3. You have jQuery, so use it – it will take all checkboxes in one go without the need for querySelectorAll

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement