Calculating numbers based on quantity

Hi Guys,

I’ve been having a look around the forum and can’t really find an answer to my problem and I was wondering whether anyone might have done this before in wappler and would mind giving some advice on it.

I need to multiply some values in a form (this bit i can do)

The problem is that there’s a number of levels I need to calculate

In example - When the value is between 0-50 It needs to calculate by a specific amount, if the value is between 51-100 it needs to be calculated by different amount, etc.

Before using Wappler i would have just posted the form to a processing page and calculate it with php then push that into a confirmation form after its calculated. I just wasn’t sure whether there was a better way to do it in wappler.

Hope that makes sense…

Thanks in advance

Ben

Hello Ben,
can you provide the exact condition which you want to use?

Hi Teodor,

I have a page with a form, in that form i have a couple of input fields.

I’m trying to calculate pricing by sqm (Square metres)

Under 30sqm = $50
Under 50sqm = $25

I saw this post: Question from a new user - capabilities of Basic version so that side of it I can handle, It’s just the part where I add the different calculation levels.

Hope that makes sense?

So it should check the entered value? If <30 then multiply by 50, if > 30 and < 50 then multiply by 25, is that right?

Hi Teodor,

That’s exactly right.

Well such a condition requires a little more complex calculations like:

If you use this as an input value, use this:
dmx-bind:value="input1.value * ((input1.value.toNumber() <= 30) ? 50 : ((input1.value.toNumber() > 30 &amp;&amp; input1.value.toNumber() <= 50) ? 25 : 1))"

If you use this as a binding on the page use this:
{{input1.value * ((input1.value.toNumber() <= 30) ? 50 : ((input1.value.toNumber() > 30 &amp;&amp; input1.value.toNumber() <= 50) ? 25 : 1))}}"

Where input1 is the id of the input which you check, so replace it.
Also there is a third condition, everything which is not < 30 or <50 - not sure how do you want to handle this, but just replace the last “1” with the number any value greater than 50 must be multiplied.

2 Likes

@Teodor another reason why we need advance text area to enter such values in the binding.

1 Like

I would love this. I have to do the same that was mentioned earlier, I offload the calculations to a server-side page for processing. I have dozens of lines of code that requires different levels of calculations just like in the example, only more of them.

I have heaps of different levels too, I just needed a general idea of whether it was an easy thing to do in Wappler.

I might just write another server side page too I think for now. Then I can pull the levels from the database too so they can be adjusted easily.