I wrote some HTML and Javascript to create a table that has input fields that appear. Here is a picture of the HTML Table. When the user keeps clicking the button to add more it looks like this: HTML Table More Input
Here is the HTML code for the table and the javascript to create more inputs:
<form action="/information.html" method="POST">
<table class="table table-borderless">
<thead>
<tr>
<th style="text-align:center">Ticker</th>
<th style="text-align:center">Shares</th>
</tr>
</thead>
<tbody id='room_fileds'>
<tr>
<td style="text-align:center">
<fieldset class="form-group">
<input type="text" placeholder="AAPL" name="stock1"/>
</fieldset>
</td>
<td style="text-align:center">
<fieldset class="form-group">
<input type="text" placeholder="100" name="weight1"/>
</fieldset>
</td>
</tr>
</tbody>
</table>
</form>
<br/>
<input type="button" id="more_fields" onclick="add_fields();" value="Add More" />
<input type='submit' value='Submit'/>
<script>
var count = 0
function add_fields() {
count++
var county = count.toString();
var objTo = document.getElementById('room_fileds')
var divtest = document.createElement("tr");
divtest.innerHTML = '<td style="text-align:center"><input type="text"></td><td style="text-align:center"><input type="text"></td>';
objTo.appendChild(divtest)
}
</script>
I am trying to use flask to get all the post input. Usually I have an input with a name such as stock1 and then I do the following with flask:
stock1=request.form.get('stock1',type=str)
However, I am unsure of how to handle this type of dynamically created inputs. I am not sure if the user will enter data into 1 or 2 or even 25 input boxes. Is there a proper way to use flask to get all of this data if it is unknown how much data the user will enter? Possibly, I would like to get all of the tickers into a list and all of the shares into another list.