Where is your code that adds up all values for the total?
User Input:
-
Quantity For Product 1: #quantity1
-
Quantity For Product 2: #quantity2
Text Elements: -
Unit Price For Product 1: #UnitPrice1
-
Unit Price For Product 2: #UnitPrice2
-
Final Price For Product 1: #FinalPrice1
-
Final Price For Product 2: #FinalPrice2
-
Total Price: #TotalPrice
export function quantity1_change(event, $w) {
let price = Number($w('#UnitPrice1').text);
let selectedQuantity = Number(event.target.value);
$w('#FinalPrice1').text = String(selectedQuantity * price);
$w('#TotalPrice').text = String(Number($w('#FinalPrice1').text) + Number($w('#FinalPrice2').text));
}
export function quantity2_change(event, $w) {
let price = Number($w('#UnitPrice2').text);
let selectedQuantity = Number(event.target.value);
$w('#FinalPrice2').text = String(selectedQuantity * price);
$w('#TotalPrice').text = String(Number($w('#FinalPrice1').text) + Number($w('#FinalPrice2').text));
}
Text Element:
-
Menu Items: #titles
-
Total Price (Sum Total of All Items): #TotalPrice
Repeater Elements: -
Item Name: #ItemName
-
Unit Price: #UnitPrice
-
Quantity Ordered: #quantity
-
Total Price of Each Item (#UnitPrice X #quantity): #price
Button Element: #CheckOut
Dataset
Create a dataset OrderForm with the same fields as your form.
Database fields
-
Item Name: ItemName
-
Quantity Ordered: quantity
-
Unit Price of Each Item: unitprice
-
Total Price (Unit Price X quantity): price
$w.onReady(function () {
let count = $w("#dataset1").getTotalCount(); // No. of items in dataset //
$w("#dataset1").getItems(0, count) // Get all items //
.then((results) => {
let sumTotal = 0;
let items = results.items;
items.forEach(item => {
sumTotal = sumTotal + Number(item.price);
});
$w("#total").text = "" + sumTotal;
// Add other calculations here //
}).catch((err) => {
console.log(err);
});
});

