Compare 2 fields

At the time of writing there is no built in way to compare 2 fields with each other. However, since Conditional Fields PRO allows you to define your own functions, you can always resort to a bit of JavaScript in order to create your own custom conditions.

Let’s say you want to show a group, only when the value of field A is less than the value of field B. You can define a function like this:

function aLessThanB($field) {
  const a = parseInt(document.getElementById('a').value);
  const b = parseInt(document.getElementById('b').value);
  return a < b;
}

Then create a condition like this:

show [a-lt-b] if [a] function "aLessThanB"

Note that, since we are going to get the values of both fields by their ID in the function itself, it doesn’t matter which field we reference. So we could just as well create the condition like this, with the exact same result:

show [a-lt-b] if [b] function "aLessThanB"

Example form

Form

    Show group if A < B

    A:
    B:

    A is less than B

    Form Code

    <p>Show group if A < B</p>
    A: [number a id:a "0"]
    B: [number b id:b "0"]
    [group a-lt-b]A is less than B[/group]
    <script>
      function aLessThanB($field) {
        const a = parseInt(document.getElementById('a').value);
        const b = parseInt(document.getElementById('b').value);
        return a < b;
      }
    </script>

    Conditional Fields (Text)

    show [a-lt-b] if [a] function "aLessThanB"