Compare and if true do a calculation

Hi, I’m trying to compare the content of a wappler variable (on a form change) to see if it matches a text string - if it does, I want to run a calculation. (if then)

I’m having a problem and not sure if what I’m trying to do is impossible or if I just have a syntax error. Code section below…

<input type="number" class="form-control" id="pizzasize" name="pizzasize" placeholder="Enter Pizza Size in Inches" value="5" data-rule-min="5" data-rule-max="30" dmx-bind:disabled="input1_group.input1_2.checked" dmx-bind:value="form1.pizzasizesq.value" dmx-on:change="var1wordsforcalculatebydropdown.value == &quot;Thickness Factor&quot; ? OnceGramValue.setValue((((28.3495 * tf.value * (((3.14159265359 * (pizzasize.value / 2).pow(2))) * 1)).round(2))))">

Can you explain outside of the code provided what is the condition you’d like to check and what needs to happen if it’s met, and what if it’s not?
Just explain it like:
I want to check if form input value 1 equals form value 2 etc.

I want to check if my variable (var1wordsforcalculatebydropdown.value) = the text string “Thickness Factor”.

If it does, I want to set the value of the variable (OnceGramValue) using this formula

((((28.3495 * tf.value * (((3.14159265359 * (pizzasize.value / 2).pow(2))) * 1)).round(2))))

else do nothing.

What is OnceGramValue - is it a variable defined in app connect? Is it a form input?
What should be its value if the var1wordsforcalculatebydropdown.value is not equal to "Thickness Factor"??

Both OnceGramValue and var1wordsforcalculatebydropdown are variables (see photo)

var1wordsforcalculatebydropdown can have 3 possible values

Thickness Factor

Weight in Ounces

Weight in Grams

If not equal to “Thickness Factor” the value of OnceGramValue should be left alone

2018-10-31_11-38-24

Ok then you need to use this as a value for the OnceGramValue variable:

dmx-bind:value="var1wordsforcalculatebydropdown.value == &quot;Thickness Factor&quot; ? ((((28.3495 * tf.value * (((3.14159265359 * (pizzasize.value / 2).pow(2))) * 1)).round(2)))) : ''"

please try this

NOTE you put this in the OnceGramValue variable value, not in the text field!

I can’t use DMX-bind:value= for this since I’m already using DMX-bind:value= for something else in the statement. And it will not allow me to have two DMX-bind:value= in the same statement

Can it work using dmx-on:change=

This is the last thing I need to work and I can eliminate 60% of my codebase

When I put in

dmx-on:change="var1wordsforcalculatebydropdown.value == &quot;Thickness Factor&quot; ? ((((28.3495 * tf.value * (((3.14159265359 * (pizzasize.value / 2).pow(2))) * 1)).round(2)))) : ''"

it does not seem to work.

No, that’s a wrong expression - it won’t change anything like this.
Probably you need to re-think the logic behind this variable value.

I don’t understand why using dmx-on:change= does not / can not work with the added conditional statement. If I leave out the conditional part it (see below) works fine. In other words, this works - but I need the condition.

dmx-bind:value="form1.pizzasizesq.value" dmx-on:change="OnceGramValue.setValue((((28.3495 * tf.value * (((3.14159265359 * (pizzasize.value / 2).pow(2))) * 1)).round(2))))"

With a setvalue it should be working, in your previous example it does not include setvalue.

dmx-on:change="OnceGramValue.setValue(var1wordsforcalculatebydropdown.value == &quot;Thickness Factor&quot; ? ((((28.3495 * tf.value * (((3.14159265359 * (pizzasize.value / 2).pow(2))) * 1)).round(2)))) : '')"
1 Like

Yes, it is working now - I think I had the setvalue in the original example I posted so was it just that I did not have the else (the two single quotes) the reason it did not work?.

Only asking so I can learn - very happy that is is working now - a big thank you for that!!!

1 Like

Not sure if it was the missing else, you can try and see the error in the console :slight_smile:

1 Like