Support » Plugin: Calculated Fields Form » Struggling with formula that requires if statement

• Resolved 83creative

(@winnard)

Hi guys,

Great plugin. I am trying to figure out a solution to my current calculated form.

I have the current formula working in my form.

(fieldname3*fieldname10)+(fieldname1+fieldname6+fieldname8+fieldname12)

This works great. What I want to achieve is an if statement on the first part of the formula.

Fieldname3 is where user enters purchase price of a house property.
Fieldname10 is a dropdown set with the following options.

< £125,000 = 0%
> £125,000 < £250,000 = 1%
> £250,000 < £500,000 = 3%
> £500,000 < £1,000,000 = 4%
> £1,000,000 < £2,000,000 = 5%
> £2,000,000 = 7%

I would like to do a formula whereby I can remove these options from the user side and the calculation works when the user enters the house value in Fieldname3. Is this possible? If so could somebody help me out??

So it would be

if ((fieldname3 < £125,000) * 0.00) +(fieldname1+fieldname6+fieldname8+fieldname12) and so on to cover the other %.

If anybody could help me it would be most appreciated.

Thanks

Dan

http://wordpress.org/extend/plugins/calculated-fields-form/

Viewing 15 replies - 1 through 15 (of 18 total)
• Plugin Author codepeople

(@codepeople)

Hi,

The equation in this case is not complex, please use the equation below:

(function(){
var v;
if(fieldname3 < 125000) v = 0;
if(fieldname3 >= 125000 && fieldname3 < 250000) v = 0.01;
if(fieldname3 >= 250000 && fieldname3 < 500000) v = 0.03;
if(fieldname3 >= 500000 && fieldname3 < 1000000) v = 0.04;
if(fieldname3 >= 1000000 && fieldname3 < 2000000) v = 0.05;
if(fieldname3 >= 2000000) v = 0.07;

return fieldname3*v+fieldname1+fieldname6+fieldname8+fieldname12;
})()

revitfactory

(@revitfactory)

Hi I would also like to do a similar result but I need to display text instead of a numerical value. I cant seem to get it working with text. here is what I have:

``````(function(){
if(fieldname12 == 0) return "Bill MOnthly";
if(fieldname12 == 0.15) return "Bill Annually";

})();``````

Many thanks

Plugin Author codepeople

(@codepeople)

Hi,

I’m sorry, but the Calculated Field requires a number as value. Remember, the calculated field is the result of a mathematical equation.

Best regards.

revitfactory

(@revitfactory)

Ah, ok thanks.

Is there another way I could get text to change based on a dropdown choice?

Basically I’m trying to get the text under the total cost to say either ‘Billed Annually’ or ‘Billed Monthly’ based on their choice higher up the page when they choose discount options:
Monthly – 0% Discount.
Annually – 15% Discount.

bob1483

(@bob1483)

Hi revitfactory
you can have two different text fields and based on what you select in dropdown one of them will appear.
just click on “show dependencies” in dropdown settings and chose one of the text fields for each choices of dropdown.

revitfactory

(@revitfactory)

excellent that works great for me. Thanks for a prompt response!

bob1483

(@bob1483)

Anytime buddy

revitfactory

(@revitfactory)

Hi, sorry just one more problem. Im trying to add custom css which has worked fine in most scenarios but i cannot get the font height to change to bold?

I created a custom css as shown below but it doesn’t work. Yet if i try changing the color: red; it works fine… even tried adding !important

``````.totalpayment {
font-style:bold !important;
}``````

revitfactory

(@revitfactory)

Sokrry just realised I had the wrong code in the last post I have code shown below but it still doesnt work. Thanks

``````.totalpayment {
font-weight:bold !important;
}``````

bob1483

(@bob1483)

Actually you dont need css to bold the font. Just use html code in the field you want it to be bold.

revitfactory

(@revitfactory)

Fantastic Thanks

energynerd

(@energynerd)

Is it possible to return a fixed value and a variable value from this formula:

(function(){
var v;
if(fieldname3 < 125000) v = 0;
if(fieldname3 >= 125000 && fieldname3 < 250000) v = 0.01;
if(fieldname3 >= 250000 && fieldname3 < 500000) v = 0.03;

return fieldname3*v+fieldname1+fieldname6+fieldname8+fieldname12;
})()

So if fieldname3 was < 125000 it could return a fixed fee i.e. return v rather than fieldname3*v?

Plugin Author codepeople

(@codepeople)

In that case you only need to replace:

if(fieldname3 < 125000) v = 0;

by

if(fieldname3 < 125000) reutrn <fixed value>;

for example:

if(fieldname3 < 125000) return 100;

The other equation’s parts don’t require be modified:

(function(){
var v;
if(fieldname3 < 125000) return 100;
if(fieldname3 >= 125000 && fieldname3 < 250000) v = 0.01;
if(fieldname3 >= 250000 && fieldname3 < 500000) v = 0.03;

return fieldname3*v+fieldname1+fieldname6+fieldname8+fieldname12;
})()

energynerd

(@energynerd)

Thank you!

energynerd

(@energynerd)

Sorry to ask again, but what happens if there is another field, fieldname2. Fieldname2 and Fieldname3 are dependent and shown based on the value selected from a radio button so that one or both can be visible.

I tried something similar to the option below but the formula would always return 100/200 respectively plus there is no way for the formula to calculate if both fields are less than 125000.

(function(){
var v;
var w;
if(fieldname3 < 125000) return 100;
if(fieldname3 >= 125000 && fieldname3 < 250000) v = 0.01;
if(fieldname3 >= 250000 && fieldname3 < 500000) v = 0.03;
if(fieldname2 < 125000) return 200;
if(fieldname2 >= 125000 && fieldname3 < 250000) w = 0.04;
if(fieldname2 >= 250000 && fieldname3 < 500000) w = 0.06;

return prec(((fieldname2*w/100)+(fieldname3*v/100)),2);
})()

Is there a way to incorporate the formula to include an if radiobox value or similar?

The final part of my question is that if a user selects the radio button so both fields are visible, enters values into each field and then changes the radiobox value so that now only 1 field is visible, the formula still calculates the value previously entered into the now hidden field. I was hoping the if radiobox value field could handle this as well?

Viewing 15 replies - 1 through 15 (of 18 total)
• The topic ‘Struggling with formula that requires if statement’ is closed to new replies.