Calculator in the forms
What the calculator can do
The calculator lets your visitors estimate prices, amounts, or other values in real time. As soon as they fill in the fields, the calculator applies your predefined formula and displays the result right away.
NOTEThe calculator works exclusively with numeric values (see the table below).
Main features
- 1 The calculator computes values from the data users enter, following the formula you predefine.
- 2 The “Calculation result” field supports mathematical operators and self-executing JavaScript.
- 3 Results can be displayed anywhere on the page by inserting a variable that looks like:
{{ form.ID.variableName.value }}
or{{ form.ID.variableName.text }}
.
- 4 A field value can be passed into the Hidden field of another form on the same page.
- 5 One result can be used as the basis for another calculation. This is useful for showing intermediate values, such as the original price and the discounted price.
NOTEThe calculator is available only in vertical forms.
Horizontal forms and quizzes are not supported.
How to add a calculator to your form
To add a calculator to any form on Flexbe, do the following:
Step 1. Go to the Elements catalog and add a vertical form
Step 2. Add the fields you need
Build your calculator using any of the supported field types marked with the special icon (Number
, Checkbox
, Radio
, Select
, Slider
, Calculation result
, Hidden field
). To include a field in the calculation, simply switch its toggle on.
Step 3. Assign variable names for all calculator fields
When setting up a field, give its variable an easy-to-understand name to use it in your formula. Make sure every variable has a unique name within the same form.
NOTEUse only Latin letters when naming variables.
Step 4. Add the “Calculation result” field
Add a Calculation result field to your form. Then enter the formula you want to use in its settings.
You can reuse this result in other formulas, for example, to calculate a discount.
Step 5. Save and check the formula
Save your changes and switch to the preview mode to make sure the calculator works correctly.
You can disable the Submit button in the form. It’s useful if you want visitors to see the calculation results without sending the form.
Creating an example calculator
Let’s build a window installation calculator that allows visitors to estimate the cost of a window along with additional options and installation fees.
We start by adding the necessary fields, enabling them for calculations, and giving each variable a unique name:
- Window height (
height
) - Window width (
width
) - Price per sq.ft. (
price
) - Additional options (
options
) - Installation fee (
installation
)
Then we add the Calculation result field with this formula:
(height * width * price) + options + installation
The calculator now shows the window cost in real time, using the details the visitor provides.
Using variables anywhere on the page
You can output calculator variables anywhere on the page, for example, inside the text or in the Hidden fields of other forms. Here’s how you can do this.
Step 1. Copy the variable from the calculation result settings.
You can choose between two options: All text or Value only.
Step 2. Paste the copied value to any place on the page where you want it to appear.
TIPVariables work in texts, button labels, Hidden fields of other forms, etc.
Supported mathematical operators
You can use the following math operators for your formulas:
width^2
orwidth**2
— raise to the nth powersqrt(width)
— square rootmin(width, 10)
— minimum value- and more (see the table below)
Operator | Description | Example |
---|---|---|
sqrt | Returns the square root of a number | sqrt(9) → 3 |
cbrt | Returns the cube root of a number | cbrt(27) → 3 |
abs | Returns the absolute value of a number | abs(-5) → 5 |
sin | Sine of an angle (in radians) | sin(Math.PI / 2) → 1 |
cos | Cosine of an angle (in radians) | cos(0) → 1 |
tan | Tangent of an angle (in radians) | tan(Math.PI / 4) → 1 |
asin | Arcsine: returns the angle in radians | asin(1) → Math.PI / 2 |
acos | Arccosine: returns the angle in radians | acos(1) → 0 |
atan | Arctangent: returns the angle in radians | atan(1) → Math.PI / 4 |
log | Natural logarithm (base e) | log(Math.E) → 1 |
log10 | Base-10 logarithm | log10(1000) → 3 |
exp | Returns e raised to the power of x* | exp(2) → Math.E ** 2 |
floor | Rounds down to the nearest integer (floor) | floor(4.9) → 4 |
ceil | Rounds up to the nearest integer (ceiling) | ceil(4.1) → 5 |
round | Rounds to the nearest integer | round(4.6) → 5 |
trunc | Truncates the fractional part of a number | trunc(4.9) → 4 |
sign | Returns the sign of a number (-1, 0, 1) | sign(-8) → -1 |
max | Returns the maximum of the arguments | max(3, 7, 2) → 7 |
min | Returns the minimum of the arguments | min(3, 7, 2) → 2 |
Table of supported fields
Field type | Calculation features |
---|---|
Checkbox | All selected values are summed up |
Select | All selected values are summed up |
Slider range | Supported without including the range of values |
List | No special features |
Number | No special features |
Hidden field | No special features |