I am new at this and trying to submit a basic form which has a dropdown list and 2 text fields. The lists value is the path of the flask route which needs to be submitted the data.
Depending on the item the user selects from the list, i would like to submit the form with data to that url, eg if user selects "a" then i would like to submit form to http://url/url1. How can this be done?
<form action="" class="form1" method="get">
<select class="form-control" id="function" name="cars">
<option value="/url1">a</option>
<option value="/url2">b</option>
<option value="/url3">c</option>
</select>
<input class="form-control" type="number" name="number1" value="">
<input class="form-control" type="number" name="number2" value="">
<input class="form-control" type="submit">
</form>
I have python flask code on server :
@app.route("/url1")
def url1():
num1=request.args.get('number1',default=-1,type=int)
num2=request.args.get('number2',default=-1,type=int)
evaluate the numbers and return render_template()
@app.route("/url2")
def url2():
num1=request.args.get('number1',default=-1,type=int)
num2=request.args.get('number2',default=-1,type=int)
evaluate the numbers and return render_template()
if i understand your question , you can solve it by jquery
code sample
$("#function").change(function() {
var action = $(this).val();
$("#form1").attr("action",action);
});
or
you can set a default action for the form and then in route do according to the selected value
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments