Calculations in Wix Code

Need to do calculations in Wix Code? This is an example that shows you how to multiply, divide, and sum using input fields, text elements, and Wix Code.

Calculations in Wix Code

The example below is a simple calculations with only the product quantity as an input field. By changing the quantity of the product, the total price excluding VAT, the VAT, and total price including VAT all automatically change.

This is the set up in the Wix Editor:

Calculations in Wix Code

This is the page code:

export function Quantity_change(event) {

    let price = Number($w('#ProductPrice').text);

    let quantity = Number(;

    $w('#TotPriceExclVAT').text = String(quantity * price);

    let percentage = Number($w('#Per').text);

    let priceexvat = Number($w('#TotPriceExclVAT').text);

    $w('#VAT').text = String(percentage * priceexvat / 100);

    $w('#TotPriceInclVAT').text = String(Number($w('#TotPriceExclVAT').text) + Number($w('#VAT').text));


This is how it looks on the live site after the quantity has been changed:

Calculations in Wix Code

Pay attention that coding summation requires a totally different approach than multiplication and dividing!

For more examples on calculations with Wix Code / Corvid, have a look at our tutorial pages Multiple Numbers Using Wix Code and Add Up Numbers with Wix Code.

Do you need help with Wix Code, or would you like us to design a beautiful, functional, and relevant Wix website for you? Contact WixCreate, we will create an online presence that works for you.