top of page

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(event.target.value);

    $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.





ABOUT WIXCREATE

Welcome to WIXCreate, your top-level WIX Partner! Our experienced team of digital professionals has built hundreds of beautiful and functional websites using the WIX platform for companies and organizations around the world.

 

We're passionate about helping businesses like yours succeed online. With our expertise in design, development, and digital marketing, we're here to support you every step of the way. Whether you're looking to create a new website, improve your online presence, or drive more leads and sales, we're here to help you achieve your goals.

HOW CAN WE HELP?

We offer the following services:

  • Design and development of new websites

  • Migration of existing websites to WIX

  • Help with managing and updating existing WIX websites

  • Ongoing website maintenance and support

  • SEO optimization to improve your website's search engine ranking

bottom of page