I am making a flask app, where the user inputs data, and a javascript function adds that data to a html table and diplays it to the user. I now want to take that table, and send it to my flask app, so it can be added to a database and the sorts. How do I send an html table to my flask app?
here is my code so far:
newroster.html
{% extends "layout.html" %}
<form method="post" id="myform" onsubmit="return false;" name="myform">
<table id="people" class="tablex">
<tr>
<th> People </th>
<th> </th>
</tr>
</table>
<label for="people"> Participants</label>
<br>
<input type="text" name="people" id="inputpeople" maxlength="15"
placeholder="Name"
value="{{ request.form['people']}}"></input>
<button type="button" id="addButton" class="button" name="add" onclick="addPeopleFunc()">
Add
</button>
<button id="button1" class="button" type="button" name="submitx" value="Submit form"
onclick="submitForm()">Submit</button>
</form>
javascript:
function addPeopleFunc() {
var input = document.getElementById("inputpeople").value;
const inputA = document.getElementById("inputpeople");
if (input) {
var table = document.getElementById("people");
var newrow = table.insertRow(1);
var cell0 = newrow.insertCell(0);
var cell1 = newrow.insertCell(1);
cell0.innerHTML = input;
cell1.innerHTML = '<button class="button" type="button" name="dellrow" onclick="dellListFunc(this)">Delete';
inputA.value = '';
}
}
function submitForm() {
people = document.getElementById("people");
data = tableToJson(people);
console.log(data);
}
flask:
@app.route('/new-roster', methods=('GET', 'POST'))
def newroster():
return render_template('newroster.html')
any help would be much appreciated