Cognito-forms – How to make the value of one field change based on changes made to another field in Cognito Forms

cognito-forms

Can I create a drop down box that shows a Code (in this case a trip code) and link it to another box where the Name of the trip corresponding to that code would be shown?

Best Answer

You can easily change the values of other fields on your Cognito Forms using calculations. Here are two common ways to do this:

  1. Add a Calculation field

    Add a Calculation field next to your Trip Code dropdown called Name of Trip. Specify a calculation for this field that calculates the name of the trip based on the code selected in the Trip Code field. For example, =TripCode = "SkiGetaway" ? "Colorado Ski Retreat" : TripCode = "Cruise15" ? "Alaskan Cruise" : "No Trip Selected"

  2. Calculate a Default Value

    As an alternative, you can also update the values of other fields on your form when changes occur by using a calculation to update the current value of a field. Many of the field types support a Default Value, which can actually be a calculation that references other fields on your form. If you added a Textbox field instead, called Name of Trip, and used the above calculation as the Default Value, the text in this field would automatically change when the trip code changes. This is useful when you still want the user to be able to change the calculated value, such as an auto-calculated end date for a reservation.

Check out our documentation on calculations for more details of how to write powerful calculations in Cognito Forms:

https://www.cognitoforms.com/support/2/calculations