Calculator Forms for E-commerce
Calculator forms are interactive e-forms that incorporate expression-based calculations into their functionality. They allow respondents to input data or make selections that are then processed in real-time to produce calculated results. For instance, a calculator form on a grocery shop website helps buyers determine the total cost of selected items. This demo shows how to build a calculator form that contains a catalog of item images with names and costs (vegetables in our example). Once a user selects an item they want to purchase, a related dropdown appears, allowing them to select the quantity. The total cost of all selected items is displayed at the bottom of the form and automatically updates with each modification.
Arrange Elements on the Form
To build the layout described above, use Panel elements with an Image Picker and a Dropdown questions inside. Each Image Picker should contain only one image and enable the multiSelect
property to let respondents both select and unselect the image. Each Dropdown should become visible only when respondents select an image to which it is attached. Use the visibleIf
property to control the visibility.
Perform Calculations
To calculate the price of each product, add an Expression question to each Panel. Use this question multiply the price of one kilogram by the selected number of kilograms. Because this question will only be used in calculations, set its visible
property to false
.
To compute the total price, create a calculated value that adds up all expression values. You can use an HTML question to display the calculated value. To exclude unselected products from the final calculation, set SurveyModel
's clearInvisibleValues
property to "onHidden"
.
Refer to the survey JSON schema (the json.js
file) for a code example.