I am a developer for Cognito Forms.
The example you included was from this blog post on three ways to implement discounts in Cognito Forms.
The syntax for the discount calculation would be:
=CouponCode = "CODE1" ? 0.15 : CouponCode = "CODE2" ? 0.25 : 0
The syntax is a bit cryptic (used by JavaScript and other C languages), but generally it is:
[condition] ? [true result] : [false result]
But you can chain them together indefinitely like:
[condition 1] ? [true result 1] : [condition 2] ? [true result 2] : [condition 3] ? [true result 3] : [false result]
The full documentation for calculations can be found on the Cognito Forms help site.
Cognito Forms supports calculations for many of the settings you can configure. Also, any time you are able to enter calculations, you are also able to just enter a literal/constant value.
Any option that supports calculations will have an = sign as a placeholder and a lightning bolt at the end, like the following:
You can click the lightning bolt to bring up the advanced editor, but you can also just enter your calculations right there.
If all you want is to provide a constant value, you can do so like this:
But if you want to write a calculation, you must start with an = sign (similar to Excel) to let Cognito Forms know you are trying to calculate something:
I suspect in your case you just need to add an = sign at the front of your calculation.
If you are trying to calculate totals by adding the amounts for selections made for Choice fields (dropdown, radio buttons, or checkboxes) or for Yes/No fields (checkbox), you can use the specific FieldName_Amount property in your calculations. For example, if you have a Choice field named Model with assigned prices, and another Choice field named Wheel Package with assigned prices, you could calculate the total of these two fields with this calculation: =Model_Amount + WheelPackage_Amount
.
Finally, any field marked to Collect Payment will automatically appear as line items at the bottom and will be automatically totaled for you. You may still need to use calculations for things like price discounts or custom line item descriptions, but simply showing and totaling line items is handled by Cognito Forms. Also, payment fields in Repeating Sections are automatically grouped when shown as line items on the invoice/receipt.
Best Answer
I am a developer with Cognito Forms.
This can be done by using a Price Field. In the Amount area you are going to be adding a calculation that checks to see if the Yes/No field is true or false, it will then add a price depending on what value it finds.
This is the calculation used with the Yes/No field titled "Yes No".
With this calculation the Yes or True value will be set to 10$ and the No or False value will be set to 20$.