0

The following are the sample code which I used on flask and Html.The Checkbox in html which will be dynamically created

sample.py

from flask import Flask,request,render_template
app=Flask(__name__)
@app.route('/')
def home():
    return render_template("pass_arr.html")
@app.route('/tr',methods=['POST','GET'])
def tr():
    s=request.form.getlist('ses[]')
    print(s)
    return "welcome"
if __name__=="__main__":
    app.run()

sample.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <form method="post" action="/tr">

        <input type="checkbox" class="openprom" name="ses[]" value="">
         <input type="checkbox"   class="openprom" name="ses[]" value="">
        <input type="submit" value="sub">



    </form>
    <script>
        $(document).ready(function(){
        $('.openprom').each(function () {
            $('.openprom').click(function(){
                if($(this).prop("checked") == true){
                    alert("Checkbox is checked.");
                    $(this).val('yes');

                }
                else if($(this).prop("checked") == false){
                    $(this).val('no');
                   alert("unchecked");

                }
            });
        });
        });
    </script>
    </body>
    </html>

I am getting only checked value.But I am trying to get both checked and unchecked value. CheckBox will be dynamically created

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • Possible duplicate of [How to get unchecked checkbox using Flask? (Or something!)](https://stackoverflow.com/questions/18161483/how-to-get-unchecked-checkbox-using-flask-or-something) – George J Padayatti Mar 16 '18 at 14:43

1 Answers1

0

Use this jQuery selector to select unchecked boxes:-

$("input:checkbox:not(:checked)")
Abhijeetk431
  • 847
  • 1
  • 8
  • 18