Skip to main content
Editted spacing and added some braces where missing
Source Link

I'm going to answer this question which was found in the comments of the question

"which becomes a question of how to submit a form without a 'submit' button.."

So it is very possible to submit a value when a user clicks on the button

{% block content %} <form id="target" action="YourViewName"> <div id="results" class="container">{{ data_load|safe }}</div> <input id='testName' type='checkbox' value='Yes' name='testName'> </form> {% endblock %} $( "#results" ).click(function() { $( "#target" ).submit(); }); 

If you want to stay on the same page, however, you're going to need to use an ajax call to pass the data back rather then use a standard submit, however This tutorial covers that topic fairly well. but a basic change to send the data back would look like

$( "#results" ).click(function() { var request = $.ajax({ type: "POST", url: "YourViewName""/YourViewName", data: {'input_value':$('#testName').val()}, dataType: "html" }).done(function(msg) { // I don'tdon''t know what you want to do with a return value... // or if you even want a return value } }); 

and the flask would look like

@app.route("/YourViewName") def example(): list_name = request.args.get("input_value") #if you don't want to change the web page just give a blank return return "" 

I'm going to answer this question which was found in the comments of the question

"which becomes a question of how to submit a form without a 'submit' button.."

So it is very possible to submit a value when a user clicks on the button

{% block content %} <form id="target" action="YourViewName"> <div id="results" class="container">{{data_load|safe}}</div> <input id='testName' type='checkbox' value='Yes' name='testName'> </form> {% endblock %} $( "#results" ).click(function() { $( "#target" ).submit(); }); 

If you want to stay on the same page, however, you're going to need to use an ajax call to pass the data back rather then use a standard submit, however This tutorial covers that topic fairly well. but a basic change to send the data back would look like

$( "#results" ).click(function() { var request = $.ajax({ type: "POST", url: "YourViewName", data: {'input_value':$('#testName').val}, dataType: "html" }).done(function(msg) { // I don't know what you want to do with a return value... // or if you even want a return value } }); 

and the flask would look like

@app.route("/YourViewName") def example(): list_name = request.args.get("input_value") #if you don't want to change the web page just give a blank return return "" 

I'm going to answer this question which was found in the comments of the question

"which becomes a question of how to submit a form without a 'submit' button.."

So it is very possible to submit a value when a user clicks on the button

{% block content %} <form id="target" action="YourViewName"> <div id="results" class="container">{{ data_load|safe }}</div> <input id='testName' type='checkbox' value='Yes' name='testName'> </form> {% endblock %} $( "#results" ).click(function() { $( "#target" ).submit(); }); 

If you want to stay on the same page, however, you're going to need to use an ajax call to pass the data back rather then use a standard submit, however This tutorial covers that topic fairly well. but a basic change to send the data back would look like

$( "#results" ).click(function() { var request = $.ajax({ type: "POST", url: "/YourViewName", data: {'input_value':$('#testName').val()}, dataType: "html" }).done(function(msg) { // I don''t know what you want to do with a return value... // or if you even want a return value } }); 

and the flask would look like

@app.route("/YourViewName") def example(): list_name = request.args.get("input_value") #if you don't want to change the web page just give a blank return return "" 
Source Link
AlexLordThorsen
  • 8.6k
  • 6
  • 57
  • 115

I'm going to answer this question which was found in the comments of the question

"which becomes a question of how to submit a form without a 'submit' button.."

So it is very possible to submit a value when a user clicks on the button

{% block content %} <form id="target" action="YourViewName"> <div id="results" class="container">{{data_load|safe}}</div> <input id='testName' type='checkbox' value='Yes' name='testName'> </form> {% endblock %} $( "#results" ).click(function() { $( "#target" ).submit(); }); 

If you want to stay on the same page, however, you're going to need to use an ajax call to pass the data back rather then use a standard submit, however This tutorial covers that topic fairly well. but a basic change to send the data back would look like

$( "#results" ).click(function() { var request = $.ajax({ type: "POST", url: "YourViewName", data: {'input_value':$('#testName').val}, dataType: "html" }).done(function(msg) { // I don't know what you want to do with a return value... // or if you even want a return value } }); 

and the flask would look like

@app.route("/YourViewName") def example(): list_name = request.args.get("input_value") #if you don't want to change the web page just give a blank return return ""