## Calculated Fields Form[resolved] if calculation (7 posts)

1. mhecht2013
Member
Posted 4 months ago #

Hi,
I have problem with a formula :
fieldname 3 is a number
fieldname 4 is a number
fieldname 5 is a number
fieldname 6 is a number
fieldname 9 is a multiple choice (4 choices)with text value

The outcome of the formula I would like dépends of the choice. Then I wrote :

``````(function() {
if ( fieldname9="100% douches") {return (fieldname3*50+fieldname4*98+fieldname5*132+fieldname6*177)
}
else if ( fieldname9="80% douches") {return (fieldname3*54+fieldname4*105+fieldname5*141+fieldname6*191)
}
else if ( fieldname9="50% douches") {return (fieldname3*59+fieldname4*115+fieldname5*134+fieldname6*211)
}
else ( fieldname9="20% douches") {return (fieldname3*64+fieldname4*125+fieldname5*169+fieldname6*236)
})()``````

It does not work. Could you help ?
Best regards.

2. codepeople
Member
Plugin Author

Posted 4 months ago #

Hi,

Without modify the fields values, try the following equation:

(function() {
if ( fieldname9=100) {return (fieldname3*50+fieldname4*98+fieldname5*132+fieldname6*177);
}
else if ( fieldname9=80) {return (fieldname3*54+fieldname4*105+fieldname5*141+fieldname6*191);
}
else if ( fieldname9=50) {return (fieldname3*59+fieldname4*115+fieldname5*134+fieldname6*211);
}
else ( fieldname9=20) {return (fieldname3*64+fieldname4*125+fieldname5*169+fieldname6*236);
})();

If the options values start with a number, the "Calculated Fields Form" extracts the number, and use it in the equation.

Best regards.

3. mhecht2013
Member
Posted 4 months ago #

But it did not work !
Anything else ?
Thank you so much.

4. codepeople
Member
Plugin Author

Posted 4 months ago #

Hi,

Could you send me the link to the webpage for checking the issue, please?

If you prefer, may send the link through our support page in:

http://wordpress.dwbooster.com/support

Best regards.

5. mhecht2013
Member
Posted 4 months ago #

6. codepeople
Member
Plugin Author

Posted 4 months ago #

Hi,

After checking the equation format exhaustively, I've detected multiple errors. The correct equation format is below:

``````(function() {
if ( fieldname9==100) {return (fieldname3*50+fieldname4*98+fieldname5*132+fieldname6*177);}
else if ( fieldname9==80) {return (fieldname3*54+fieldname4*105+fieldname5*141+fieldname6*191);}
else if ( fieldname9==50) {return (fieldname3*59+fieldname4*115+fieldname5*134+fieldname6*211);}
else if ( fieldname9==20) {return (fieldname3*64+fieldname4*125+fieldname5*169+fieldname6*236);}
})();``````

[Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

7. mhecht2013
Member
Posted 4 months ago #

It works.
Thanks a lot for your support.
Best ragards