How to put boolean flag in button element between Javascript and Flask

It’s been 1 weeks i able not to find the solution, i have a web that create from Flask and javascript.

I have a table on my index.html like this :

<form class="testform" method="post" action="/">
            <table class="table">
              <thead>
                <tr>
                  <th>Number</th>
                  <th>Detail</th>
                  <th>Keterangan</th>
                </tr>
              </thead>

              <tbody class="tbody">
                <!-- <tr>
                  <td>01</td>
                  <td>Mesin printer</td>
                   <td>
                    <button
                      type="submit"
                      class="btn--action"
                      data-id="312324"
                      name="submit-button"
                      value="true">
                      Unduh
                    </button>
                  </td>
                </tr>
                <tr>
                  <td>02</td>
                  <td>Layar</td>
                  <td>
                    <button
                      type="submit"
                      class="btn--action"
                      data-id="312324"
                      name="submit-button"
                      value="true">
                      Unduh
                    </button>
                  </td>
                </tr> -->
              </tbody>
            </table>
          </form>

everytime i click the button with “submit-button” as name attribute, my goal is to read or passing the value attribute in Flask,

However, i also have create this table in use insertadjacentHTML in javascript like this :

const html = `<tbody class="tbody">
                <tr>
                  <td>01</td>
                  <td>Mesin printer</td>
                  <td>
                    <button
                      type="submit"
                      class="btn--action"
                      data-id="312323"
                      name="submit-button"
                      value="true"
                    >
                      Unduh
                    </button>
                  </td>
                </tr>
                <tr>
                  <td>Divisi</td>
                  <td>Divisi</td>
                  <td>
                    <button
                      type="submit"
                      class="btn--action"
                      data-id="312324"
                      name="submit-button"
                      value="true"
                    >
                      Unduh
                    </button>
                  </td>
                </tr> 
              </tbody>`
			  
		tbody.insertAdjacentHTML("afterbegin", html);

		tableContainer.classList.remove("hidden");
           document.querySelector(".form").scrollIntoView({ behaviour: "smooth" });

  tbody.addEventListener("click", function (e) {
   

    if (e.target.classList.contains("btn--action") && e.target.dataset.id) {
		//Some Fetch ?
	}
	
}

This is my python.app

@app.route('/', methods=["POST"])
def donglot(): 
    
    global tanda
    global inventaris_url
    print(tanda)

    

    if not tanda:
        inventaris_url = request.form.get("inventaris_url")    
        appData= extractappDatafromUrl(inventaris_url )

        tanda = True
        return jsonify(data=appData)

i tried put request.form.get(“submit-button”) or put request.form[“submit-button”] the result is None or Error.

Kindly please help.
Thank you

I don’t think data from regular buttons are submitted to the server.

Could you use a checkbox instead? See, for example, Basic native form controls - Learn web development | MDN

1 Like

Okay, if i use checked box, how can i put syntax on the flask instead?

Thanks

I’m not at a computer right now, but this is something you can investigate: put a checkbox in your form, submit it to the server and see what’s in request.form (by printing it out, for example). Do that for the two cases: when the checkbox is checked and when it isn’t.