• Resolved ludov

    (@ludov)


    Hi!

    First of, nice plugin ??

    I’m not sure which is the best way to solve this, if I should use jQuery externally from the entire plugin or if there is some smarter solution.

    What I am trying to accomplish:

    Basically I have 3 forms, which all contains the same variables a, b, c and d.

    In form one I use a to calculate b, c, d.
    In form two I use b to calculate a, c, d.
    In form three I use d to calculate a, b, c.

    and so forth…

    When I enter a in form one I would like the predefined values in form two and three to match the results of form one.

    So when I put in Form 1: a = 1
    I would like Form 2 & 3: a = 1, b = form1.b, c = form1.c etc etc

    So all the predefined values in other forms would be determined by the latest calculation in the current form.

    I hope my explanation isn’t too messy..

    Cheers ??

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

    (@codepeople)

    Hello @ludov,

    In reality, the forms in a same page have assigned a consecutive number as _1 for the first form in the page, _2 for second, _3 for third, and so on, and the same consecutive is used in the fields names, so, you can insert in the second form a “HTML Content” field with a code similar the following one as its content:

    <script>
    jQuery(document).on('change', '#fieldname1_1', function(){jQuery('#fieldname1_2').val(jQuery(this).val()).change();});
    
    jQuery(document).on('change', '#fieldname2_1', function(){jQuery('#fieldname2_2').val(jQuery(this).val()).change();});
    
    jQuery(document).on('change', '#fieldname3_1', function(){jQuery('#fieldname3_2').val(jQuery(this).val()).change();});
    </script>

    Use the same solution with the third form, but this time replacing _2 by _3

    and that’s all.
    Best regards.

    Is it possible to use the value of a “Calculated field in From 1” in “another Calculated field in Form 2” if I have both forms in the same page? If not, is there any other way to achieve this?

    Plugin Author codepeople

    (@codepeople)

    Hello,

    I’ll assume in my example you need to implement the equation: fieldname17 in the first form + the fieldname123 in the second form, and the calculated field is in the second form. There are multiple alternatives, I will explain one of them.

    1. Assign a class name to the field in the first form, to allow insert this form as the second, third or fourth form in the page without affecting the code, for example: my-external-field

    2. Insert a hidden field in the second form, for example: fieldname345, with the class name: my-auxiliary-field

    3. Insert a HTML content field in the second form with the piece of code:

    <script>
    jQuery(document).on('change', '.my-external-field input', function(){
    jQuery('.my-auxiliary-field input').val(jQuery(this).val()).change();
    });
    </script>

    4. And finally, the equation to associate with the form would be simply:

    fieldname123+fieldname345

    The process is simple, I have inserted an auxiliary field in the second form whose value is being update when the value of the field in the external form is modified, and then, I’m using the auxiliary field in the equations as usual.

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘“Connecting” Forms in some way’ is closed to new replies.