Problem with creating calculating form [Solved]

Hi again!

I don´t know what I´m missing now. I created calculating form on my website, but instead of adding the numbers up it just line ups them one after another.

So i created form, which has first dropdown, which has options with set values.
Second dropdown has the same.
Then there is the button, where I put the OnClick function.
Then there is field, where the total sum should go.
But instead, it just lines up the numbers. Example in picture:


The values are set to be 2000+1000, which should add up to 3000.
But as you can see, sounds good, doesn´t work.

Here is the line of code i wrote to export function:

export function button3_click(event) {
const puu = $w(‘#puu’).value
const maali = $w(‘#maali’).value
const priceOffer = (puu + maali)
$w(‘#hinta’).value = priceOffer;
}

Thanks in advance, if you guys have any tips and tricks for this.

Hi,

Thats because it takes it as String, which act like that ( adding the two strings together ).
So, you should parseInt the Numbers when you do the calculation, then return it as String when you want to display it. Ex:

 let x = parseInt($w("#dropdown1").value,10); 
 let y = parseInt($w("#dropdown2").value,10);

    $w("#text3").text = String(x+y)

Hope this helps!

Best,
Mustafa

Thank you so much, that solved the problem, feeling kinda dumb right now :´´D

Sincerely,
Niko