0

First see that post:

Get value with JQuery in gravity form

i'm trying this code but... nothing happend. Step by step i did:

  1. Fresh WP installation.
  2. Install Plugin Gravity Forms
  3. Create Form1 (Id of form = 1)
  4. Create Form2 (Id of form = 1)
  5. Add 5 number fields to Form2 (ids of fields are: 1,2,3,4,5)
  6. Add HTML field
  7. Put this code on HTML field:

    <script>
    gform.addFilter( 'gform_calculation_result', function(result, formulaField, formId, calcObj ){    
        if ( formulaField.field_id == "2" ) {
            var field_five = jQuery('#input_2_5').val();
            result = field_five * 12;
        }
        return result;
    });
    </script>
    
  8. Save changes to Form2.

  9. Clicked to preview of Form2

When writing the value 10 in the field (field ID = 5), the value of the field (field ID = 2), should appear with the value 120.

But nothing happens when I show the form and complete the fields.

What am I doing wrong?

Community
  • 1
  • 1
Ivan
  • 17
  • 1
  • 6
  • Well, I have some progress. Since version 1.8 Gravity Forms, the function "gform_calculation_result" is deprecated. What is his replacement? – Ivan May 15 '14 at 20:32
  • Don't know about a replacement but when I did something similar with radio buttons I needed to add a trigger `jQuery( "#input_1_5" ).click(function() {` to fire my own function, which did the maths and set the other field's value. I imagine you could also use `jQuery( "#input_1_5" ).change(function() {` – Steve Nov 14 '16 at 15:51
  • Then went for `what_checked_21 = jQuery('input[name=input_21]:checked').val()` to get the value using the iD of the element found from doing "View Source" on the form. Not sure what the equivalent would be for changed perhaps `what_checked_21 = jQuery('input[name=input_21]:changed').val()` – Steve Nov 14 '16 at 16:00
  • Got that from here but couldn't find it before: http://stackoverflow.com/questions/2204250/check-if-checkbox-is-checked-with-jquery – Steve Nov 14 '16 at 16:34

1 Answers1

1

The function gform_calculation_result is deprecated but the addFilter version isn't as it was only introduced in Gravity Forms 1.8

Did you update the script to work with your form, for example, is the id of your calculation field 2, if not you will need to change the formulaField.field_id == "2" part of the script. In that script you will also need to update #input_2_5 to match the id of the input you are retrieving the value for, that input id is targeting field 5 on form 2. You can confirm your field id by using the browser's document inspector to view the HTML for the field.

richardW8k
  • 756
  • 8
  • 11