title: Flask Dynamic dependent dropdown list
body: <p>I started reading into some flask application programming and I have been trying to get drop down menu to work, but so far I have had no luck. What I want to do is, when the user selects a Type of Food from the first dropdown list, it should get the corresponding list from the database and fill the second set of drop down list. I do not know how to make it send a quick request once a selection is made. I really don't understand what should be done here.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
    &lt;div&gt;
      &lt;form action="{{ url_for('test') }}" method="POST"&gt;
        &lt;div&gt;
          &lt;label&gt;Food:&lt;/label&gt;
          &lt;select id="food" name="food" width="600px"&gt;
          &lt;option SELECTED value='0'&gt;Choose your fav food&lt;/option&gt;  
          {% for x in food %}
            &lt;option value= '{{ x }}'&gt;{{x}}&lt;/option&gt;
          {% endfor %}
        &lt;/select&gt;
          &lt;!-- After a selection is made, i want it to go back to the database and fectch the results for the below drop box based on above selection --&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;label&gt;Choose Kind of Food:&lt;/label&gt;
          &lt;select id="foodChoice" name="foodChoice" width="600px"&gt;
          &lt;option selected value='0'&gt;Choose a kind&lt;/option&gt;
          {% for x in foodChoice %}
            &lt;option value= '{{ x }}'&gt;{{x}}&lt;/option&gt;
          {% endfor %}
        &lt;/select&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;input type="submit"&gt;
        &lt;/div&gt;
      &lt;/form&gt;
    &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>app.html</strong></p>
  
  <pre><code>@app.route('/', method = ['GET', 'POST'])
  def index():
      foodList = [ i.type for i in db.session.query(FoodType)]
      return render_template('main.html', food=foodList)
  
  @app.route(/foodkind', method = ['GET', 'POST'])
  def foodkind():
          selection = request.form['foodChoice']
          foodKind = [ i.kind for i in db.session.query(FoodType).filter(FoodKind == selection)]
          return render_template('main.html', foodChoice = foodKind)
  </code></pre>
  
  <p>I have looked at many questions and I have not yet found anything simple that would help me. It would be great if someone can demo a code for me so I can look and learn from it.</p>