Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Flask Javascript oncondition to POST request without using submit

My app example involves sending a list of states and cities (blank list in GET request) in USA to HTML. User wants to select list of state and immediately on selection see the list of cities applicable to state that was selected. Then after selecting both the state and the city, user will post request with state and city name to the server. I want to know how to add JS oncondition event in my select tag in HTML for implementing it.

My Flask code:

    @app.route("/states")
    def states():
    df = pd.read_csv('df.csv')
    states = df['State'].to_list()
    states = set(states)
    states = list(states)
    states.sort()
    cities = []
    if request.method == 'POST':
        state = str(request.form['state'])
        cities = df[df['State'] == state]['City']
        return render_template('states.html', states = states, cities = cities)
    else:
        return render_template('states.html', states=states, cities=cities)

My HTML Code:

    <form action="{{ url_for('states') }}" method="POST">
    <label style="width: 200px; margin-left: 20px">Select state</label>
    <select name="state" style="margin-left: 20px">
         {% for states in states[0:] %}
         <option>{{ states|safe }}</option>
         {% endfor %}
    </select>
          <label style="width: 200px; margin-left: 20px">Select city</label>
    <select name="strike" style="margin-left: 20px">
         {% for cities in cities[0:] %}
         <option>{{ cities|safe }}</option>
         {% endfor %}
    </select>
    </form>
          <button type="submit" class="section_button" value="Submit">Submit</button>

I appreciate any guidance.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda