index.html contains:
<div class="result">{{ result|safe }}</div>
I have a list of inputs for 4 separate checkboxes that looks like this:
<ul class="filterSection">
<li>
<strong>Show:</strong>
<input checked="true" type="checkbox" name="check" value="value1"/>
<label>First</label>
</li>
<li>
<input checked="true" type="checkbox" name="check" value="value2"/>
<label>Second</label>
</li>
<li>
<input checked="true" type="checkbox" name="check" value="value3"/>
<label>Third</label>
</li>
<li>
<input checked="true" type="checkbox" name="check" value="value4"/>
<label>Fourth</label>
</li>
</ul>
This is the part I need help with. In javascript, I need to get these 4 values every time a checkbox is checked or unchecked and send all 4 values to server without page refresh. Then I will do something to data based upon these 4 values, and then send new data back. I need to retrieve value1, value2, value3, value4 in flask and know if they are checked/unchecked. Here's what I attempted so far:
$(function() {
$.getJSON('/_filter', {
b: $('input[name="check"]').val(),
}, function(data) {
$('.result').html(data.result)
return false;
});
});
Lastly, in my flask app, I have:
@app.route('/_filter')
def filter_results():
value = request.args.get('b') ## I don't know how to get all 4 values
##compare the 4 values
##update index page with newdata based upon the values of the checkboxes
return jsonify(result=newdata)