I'm using Bootstrap with Flask Python.
request.form.get("name")
#name is the name of the form element(checkbox)
<label class="btn btn-danger pzt active">
<input type="checkbox" name="name" value="1" data-id="0"> Check
</label>
When checkbox is checked, parent label has class "active", I want to get if checked box is checked. Is there any way or methods?
Checking if a checkbox is checked First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.
Is there a way to do this? If you give all the checkbox widgets the same name attribute, and a value attribute with the corresponding name, the form should send a list of names. You can retrieve this using the getlist() method of request.
you can try the following:
HTML:
<div class="checkbox">
<label>
<input type="checkbox" name="check" value="edit"> New entry
</label>
</div>
In flask:
value = request.form.getlist('check')
This will give you the value of the the checkbox. Here value will be a list.
value = [u'edit']
You can also get value of multiple checkboxes with same name attribute.
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