diff --git a/src/templates/index.html b/src/templates/index.html index e76427e..0361612 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -111,11 +111,16 @@ document.getElementById('submit-button').disabled = !(food && weight); } + function addProduct() { const foodInput = document.getElementById('my_combobox'); const weightInput = document.getElementById('weight'); const food = foodInput.value; - const weight = weightInput.value; + let weight = parseFloat(weightInput.value); + const portions = Math.max(parseInt(portionsInput.value, 10), 1); // Stellt sicher, dass mindestens 1 Portion angegeben wird + + // Teilen des Gewichts durch die Anzahl der Portionen und Aufrunden + weight = Math.ceil(weight / portions); fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`) @@ -195,6 +200,9 @@ function updateTotalNutrition() { + + +