Vorbly <Code>
CODING MADE EASY WITH VORBLY
WIX CODE CALCULATIONS - SUM NUMBERS
Need a customized shopping cart? This tutorial will show you how to sum prices of all products using Wix Code. We will provide you with the webpage elements and sample codes required to implement this feature.
THE DEMO
THE ELEMENTS
The Page
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
THE CODE
Page Code
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));
}
COMMENTS
I'm a paragraph. Click here to add your own text and edit me. It's easy.