Changing values on screen with code

I’m a complete noob when it comes to wix and I have a problem.
I want to change the price displayed when the customer fills in a number field. How do I do this? When the customer changes the field called Lengde(length) i want the price to be multiplied by this value. Can someone help?

Hi Paudun ,

Depending on how you get the data of that product, but anyway, you can set an onChange() function that takes the [ lengde ] value and multiply it with the price :

$w("#lengde").onChange( (event, $w) => {
  let lengde= event.target.value;  // "new value"
  let total = lengde * price ;
  $w("#price").text = total; //set the text to the total price
});

FOR MORE INFORMATION PLEASE SEE - onChange API

Best,

Mustafa

The price shown on the product is depending on the diamater selected. 8mm costs 50 per meter, 10mm is 75 and 12mm is 100. 8mm is chosen by default. Does your code multiply 50 with the length? What if the user chooses 10mm afterwards, which costs 75 per meter. Does the code take this into consideration?

Where do I put the code above exactly? In frontend, backend or somewhere else?

Ok I got a premium plan now so I guess I put the code in the product page?
How do I reference the option values associated with a product? I have been trying something like this but I can’t figure it out;

$w(“#productPage1”).customTextField.Lengde.onChange( (event, $w) => {
});
I get an error on customTextField saying it doesn’t exist on #productPage1.

I figure i have to use the information in the picture below.

Thanks for any help :slight_smile:

Wix provides many resources to help users learn how to get the most out of Wix Code. We encourage users to take advantage of these resources which include video tutorials, full app examples (which can be loaded into the user’s editor), API documentation, and a wealth of articles describing a wide range of topics - from beginner to advance. I would recommend starting with the Wix Code Basics to see how to get started using Wix Code.

I’ve looked through the code basics and I can’t find anything that deals with my problem. First of all there’s no onChange event associated with productpage1. All I get is this;


According to the cheat sheet ‘price’ is an attribute in productPage. But how do I reference it? I’ve tried something like this;

$w('#productPage1').getProduct().StoreProduct.price 

but it doewsn’t work. I’m asking for a specific thing here, could I please get a specific answer? I need to know the syntax.