I have an html form that sends data to my flask application. In addition, to the form's input fields, I also want to pass data from a DIV's innerHTML. I've been able to get data from the input fields to pass over to the flask side, but I haven't been able to get the DIVs innerHTML.
I've read a lot of questions on here that seem similar. But the answers for those questions all revolve around using json to pass the data. However, I don't think my data fits the json format since it's being generated dynamically by the user.
So how can I pass data from a DIV's innerHTML? Am I right in assuming that this isn't a case for json. Here's what I've tried:
When I run the code below, the data for amount comes over in the console. The innerHTML returns 'NONE'
HTML
<form id="action_id" action="/" method="post">
<div class="row">
<div class="col-6" id="action_container">
<input class="col-12 action_info" type="text" id="amount" name="amount" placeholder="Amount">
</div>
<div class="col-5 hole_cards" id="hole_cards">
<div class="row">
<div class="col-12 board" id="board">
<div class="col-1 cardz" id="flop_one" name="flop_one"></div>
<button id="action_button" type="submit" value="submit">Submit</button>
</div>
</div>
</form>
JAVASCRIPT
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#action_id').onsubmit = function() {
const myform = document.querySelector('#action_id');
let data = new FormData(myform);
fetch("/", {
"method": "POST",
"body": data,
})
.then(response => response.text)
.then(data => {
flop_one = document.querySelector('#flop_one').innerHTML;
})
.catch(error => {
console.log('Error:', error);
});
return false;
}
});
PYTHON
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "GET":
return render_template("index.html")
elif request.method == "POST":
flop_one = request.form.get("flop_one")
app.logger.info(flop_one)
amount = request.form.get("amount")
app.logger.info(amount)
return render_template("index.html")