1. Home
  2. Docs
  3. FAQ
  4. How can I change a value conditionally?

How can I change a value conditionally?

Let’s say you have 2 fields, and you would like to implement this logic:

  • If field 1 has the value “X”, then field 2 should get the value “Y”
  • If field 1 has the value “Y”, then field 2 should get the value “Z”

At this time it’s not possible to change values dynamically with Conditional Fields for Contact Form 7. You can only show/hide fields dynamically. This should be solved once I have implemented calculated fields in the PRO plugin.

For now, you will need to solve this by writing some custom JavaScript. Something like this: (you could add this at the bottom of your form code)

<script>
(function($){
  const $field1 = $('#field1');
  const $field2 = $('#field2');
  $field1.on('change',function(){
    if ($field1.val() == 'X'){ $field2.val('Y'); }
    if ($field1.val() == 'Y'){ $field2.val('Z'); }
  });
})(jQuery);
</script>

Related issues:

Was this article helpful to you? Yes No

How can we help?