Skip to content
Advertisement

store html checkbox value into list using flask, jinja2

I’m in need of some help. I am using flask and I have had an HTML page with a bunch of checkboxes. They are ordered as option1, option2, and option3 and then under the options, there are a number of boxes to check. I am trying to keep track of what all boxes have been checked for which option and store that information into a list.

currently my logic is to use some for loop within the HTML file using Jinja2 and try to set some unique name tag in the form such as name=”{{getboxitem}}” However my logic is only working vertically across option1 but its not able to track if I have checked a box in option2 and option3. Is there any suggestions that could help resolve this.

Also, one other strange thing about this is I can clearly see the name of my checkbox form is “option2checkbox1” however in the python route when I request this via request. forms its setting to none as if the value is not existing.

JavaScript

Here is my HTML file

JavaScript

Advertisement

Answer

The Answer was to move the for loop under the form. After debugging I realized I was creating three form’s so looks like when I do the request.form.get it was not in the form it was looking for.

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