0
<select class="tag" name="Tag" >

    <option value="1">Option-1</option>
    <option value="2">Option-2</option>
    <option value="3">Option-3</option>

</select>

Here is the code i'm using in a form, I'm a beginner and i have no idea how to get the value of selected option.I'm using flask as backend. Would you please help me with it?
Please explain for both cases:
1. Getting the value after form submit
2. Getting the value just after selection (In order to add content to the page based on the selection)

davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

1

Case 1:

In the view function that handles the form, use request.form to get the input value:

@app.route('/foo', method=['GET', 'POST'])
def foo():
    if request.method == 'POST':
        value = request.form.get('Tag')
    ...

Case 2:

In this case, you will need to use JavaScript to create an event listener function that triggered when selected. You can fire AJAX request to get data in the event listener function.

Grey Li
  • 11,664
  • 4
  • 54
  • 64