I have a form that looks like this:
<form id="settings" action="{{ url_for("load_settings") }}" method="post">
...
<label for="m_r">Interval 1</label>
<input type="text" name="morn_r" id="m_r">
<label for="d1_e">Enabled</label>
<input type="checkbox" name="d_enabled" id="d1_e" value="off" onclick="toggle_check(this)">
</form>
This is the toggle_check
function:
function toggle_check(check) {
if (check.value=="on") {
check.value="off";
}
else {
check.value="on";
}
}
Here's my Python:
@app.route("/settings", methods=["POST", "GET"])
def load_settings():
if request.method == "POST":
settings = list(request.form.values())
print(settings)
return render_template("settings.html")
If I leave the text inputs empty but click the checkbox, here is what gets printed: [..., '', 'on']
Now, if I also leave the checkbox empty this is what gets printed: [..., '']
. For some reason it doesn't add the value of the checkbox...
I don't know how to fix this. Could someone please help?
Thanks.