Vorbly Code | WIX CODE CALCULATIONS - SUM NUMBERS

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

1/2

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.

No comments. Be the first to leave a comment.

I have a text element to show the result of a calculation based on a dropdown selection, but it only show the result of the previous selection not the actual.

this is the code:


import wixData from 'wix-data';

$w.onReady(function () {
});
export function dropdown5_change(event, $w) {
let sk = $w('#skilldmg').value;
let a = $w('#unitatk').value;
$w("#dataset2").setFilter( wixData.filter().eq("titleAlias", $w("#dropdown5").value));
$w('#text29').text = String(Math.round(a*sk));
}

some help please..thanks

liu

Jun 12, 2019

1

Hi liu,

Thanks for writing to us.

Is your dropdown element in a repeater? If that is the case, you might need to use an $w("#dropdown5").onChange(async (event, $w).

You can refer to our tutorial for more information.

https://www.vorbly.com/Vorbly-Code/WIX-REPEATER-ANIMATE-INDIVIDUAL-ITEMS

Hope it helps!

Andrew (Vorbly)

Jul 01, 2019

1

Hi, I like the code, I was just wondering, if I have more then 20 products in my webshop, how can I make the string for the total price just one time and call to that one in eight export function change event?

thanks in advance!

Karel

Nov 04, 2019

0

Test

The Tester

Nov 23, 2019

1

WEB DESIGN & DEVELOPMENT SOLUTIONS

GET PROFESSIONAL HELP