mardi 19 janvier 2021

Return textbox value if checkbox is selected

I have a form where the user can select items using checkboxes and enter the quantity of the item they want. Is there a way to return only the quantity of the items that have their checkbox selected. Currently, req.body.qty retrieves the quantity values for all items even if their checkbox is not selected.

<% availableFood.forEach(function(food_item){ %>
                <tr>
                        <td><input type="checkbox" name="checkbox[]" value= <%= food_item.name %>></td>    
                        <td><input id="qty" type="text" name="qty" 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>
                <% }) %>    



Aucun commentaire:

Enregistrer un commentaire