• Resolved Niko

    (@deter)


    Hi,

    I would like to have two fields that calculate each other dynamically.

    Example : fieldname1 = fieldname2 * 2 AND fieldname2 = fieldname1 / 2

    I want that as soon as I type a value in a field, the calculation is done in the other field.

    Thank you in advance for your help

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @deter

    In this case, you should insert two calculated fields in the form, fieldname1, and fieldname2, and enter the respective equations in their “Set equation attribute”.

    fieldname2*2 in the settings of fieldname1
    fieldname1/2 in the fieldname2 settings.

    And very important to prevent endless loops, tick the “If the value entered manually, no evaluate equation” checkbox in both fields settings.

    Best regards.

    Thread Starter Niko

    (@deter)

    Thanks for the solution, but when I try a more complex calculation it works in one direction but not when I change the other field.

    Example, I added two radios buttons “fieldname3” with values “0.2” and “0.1”.

    For the calculated field “fieldname1” the settings are : fieldname2-fieldname2*fieldname3
    And for the calculated field “fieldname2” settings : fieldname1+fieldname1*fieldname3

    When I enter a value in fieldname1 my fieldname2 is calculated. But when I modify fieldname2 nothing happens, the script crashes and no more calculation works. Also if I start with fieldname2.

    Best regards.

    • This reply was modified 2 years, 8 months ago by Niko.
    • This reply was modified 2 years, 8 months ago by Niko.
    Plugin Author codepeople

    (@codepeople)

    Hello @deter

    Please, insert an “HTML Content” field in the form with the following piece of code as its content:

    <script>
    jQuery(document).on('keydown', '.cff-calculated-field input', function(){
    jQuery(':data(manually)').data('manually', 0);
    });
    </script>

    Best regards.

    Thread Starter Niko

    (@deter)

    Great everything works, THANK YOU very much

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fields that calculate the result of each other’ is closed to new replies.