Submitting form using selection value with form data

Shinu S

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()
safiqul islam

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.

edited at
0

Comments

0 comments
Login to comment

Related

DropDown Selection not submitting to Form

Submitting form with photo data using ajax and mvc

Problems in submitting form data using ajax

amp form not submitting form data

Form is not submitting data on mobile

Submitting form data to database

Submitting the form using jquery

Go to the url of the selection after submitting the form

Session loses its data or value after form submitting in php

Not able to get form element's value after submitting form using this.form.submit();

Not submitting default value in GET form

Display the data entered in a form before submitting the form

selecting the value and then submitting the form using vue.js dosent work

React Router redirect after submitting a form using the input value

Codeigniter 3.1.9 Form not submitting data

submitting form data to MySQL Issue

Html Form not submitting data to server

Form not submitting with large amounts of data

Request body is undefined when submitting Form Data object using supertest

How to send data to servlet using ajax without a submitting form

Submitting large amount of form data to PHP using POST

Submitting a form with submit() using Promise

Issue on Submitting a Form using jQuery

form is not submitting using react and formik

Submitting a form using Requests Python

Submitting Form using jquery AJAX

Form is submitting only the final row data in a foreach loop, not the correct selection information

How to calculate two input form fields and put the value in another without submitting the form using jquery with JSF

adding an input value and submitting the form on load

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive