I want to get the value of the textboxes that correspond to checked checkboxes for each item in my SQL table. Below, I have a html table of all the items in my SQL table and I have some javascript code that is supposed to return the values of the textboxes that correspond to checked checkboxes. Am I doing it correctly and how do I get the return value of the javascript function in Node.js?
<form method="POST" action="/topic7/mid-term/calculate">
<table style="width:100%">
<tr>
<th>Selected</th>
<th>Amount</th>
<th>Name</th>
<th>Typical values</th>
<th>Unit of typical values</th>
<th>Calories</th>
<th>Carbs</th>
<th>Fat</th>
<th>Protein</th>
<th>Salt</th>
<th>Sugar</th>
</tr>
<% availableFood.forEach(function(food_item){ %>
<tr>
<td><input type="checkbox" name="checkbox[]" value= "<%= food_item.name %>"></td>
<td><input type="text" name="amt" value= "1" style="width: 30px;"></td>
<td><%= food_item.name %></td>
<td><%= food_item.typical_values %></td>
<td><%= food_item.unit_of_the_typical_value %></td>
<td><%= food_item.calories %></td>
<td><%= food_item.carbs %></td>
<td><%= food_item.fat %></td>
<td><%= food_item.protein %></td>
<td><%= food_item.salt %></td>
<td><%= food_item.sugar %></td>
</tr>
<% }) %>
</table>
<p><input type="submit" value="Calculate sum" onclick='getAmount("checkbox","amt");'/></p>
<script>
function getAmount() {
var checkbox = document.getElementsByName('checkbox');
var amount = document.getElementsByName('amt');
var amt = '';
for(var i = 0; i < checkbox.length; i++) {
if(checkbox[i].checked == true) {
amt += amount[i].value + ',';
}
}
return amt;
}
</script>
</form>