title: In Flask, is there a way to have multiple checkboxes invoke different functions on an HTML input tag?
body: <p>I have an HTML file with an input tag and two checkboxes. In a Python file I have two functions meant to act on the input tag depending on which checkbox is selected. For some reason, the function meant to calculate the gc content does not work; only the first function seems to work. How do I fix this?</p>
  <p><strong>HTML Code</strong></p>
  <pre class="lang-html prettyprint-override"><code>    &lt;form action=&quot;&quot; method='POST' &gt;
          &lt;input name=&quot;sequence&quot; type=&quot;text&quot;&gt;&lt;br&gt;
          &lt;input type=&quot;checkbox&quot; id= &quot;count_nuc&quot; name=&quot;check&quot; value=&quot;check&quot;&gt;
          &lt;label for=&quot;count_nuc&quot;&gt;Count nucleotides&lt;/label&gt;
      
          &lt;input type=&quot;checkbox&quot; id= &quot;gc_content&quot; name=&quot;check&quot; value=&quot;check&quot;&gt;
          &lt;label for=&quot;gc_content&quot;&gt;GC content&lt;/label&gt;&lt;br&gt;
      
          &lt;button type=&quot;submit&quot; value=&quot;submit&quot;&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
              
      {% if gc_percent %}
      &lt;p&gt;GC Percent: {{gc_percent}}&lt;/p&gt;
      {% endif %}
      {% if new_dict %}
      &lt;p&gt;Count nucleotides: {{new_dict}}&lt;/p&gt;
      {% endif %}
  </code></pre>
  <p><strong>Python Code</strong></p>
  <pre class="lang-py prettyprint-override"><code>    from flask import Flask, render_template, request
      
      app = Flask(__name__)
      
      
      @app.route(&quot;/&quot;, methods=['POST', 'GET'])
      def count_nucleotides():
          new_dict = {}
          nucleotides = ['A', 'C', 'T', 'G']
          seq = request.form.get('sequence')
          if request.method == 'POST' and 'sequence' in request.form and request.form.get(&quot;check&quot;):
              for i in seq:
                  if i not in nucleotides:
                      return 'Invalid nucleotide(s) found'
                  else:
                      for j in nucleotides:
                          if j == i:
                              new_dict[i] = seq.count(i)
          return render_template('calculator.html', new_dict=new_dict)
      
      
      def gc_content():
          gc_percent = 0
          seq = request.form.get('sequence')
          if request.method == 'POST' and 'sequence' in request.form and request.form.get(&quot;check&quot;):
              gc_percent += (round(((seq.count('G') + seq.count('C')) * 100 / len(seq)), 2))
          return render_template('calculator.html', gc_percent=gc_percent)
      
      
      app.run(debug=True)
  </code></pre>