Get value using jQuery in gravitational form

I am trying to add a formula to my gravitational form (WordPress), which includes exponent.i can not use the built-in calculator, since there is no exponent function. its basically a loan calculator where.

r = rate; (form_id = 4) / 12

p = loan amount; (form_id = 1)

D = Duration (form_id = 2, [drop-down menu]) * 12

X = p (g / 1- (1 + g) ^ - D)

X = repayment

Now I get r, p and D from the form in the form of drop-down and written numbers.

so far I have put the HTML field and pasted this code into it:

<script> gform.addFilter( 'gform_calculation_result', function(result, formulaField, formId, calcObj ){ if ( formulaField.field_id == "2" ) { result = /****/; } return result; }); </script> 

I don't have bg programming, and I got it from a member of the support team.

I understand that this code will replace the calculation of field_id 2 (which shows X = [monthly repayment] with the result of my formula β†’ "/ **** /"

But I need to write a formula, and I don’t know how to get the values ​​from the form using jQuery and put them in the formula.

I learned the math functions of JavaScript from W3school and another website, so I have no problem writing a formula. I just need help with jQuery to get the value.

I was wondering if anyone can help me with this?

+1
javascript jquery wordpress gravity-forms-plugin
source share
1 answer

You can capture field values ​​using jQuery . val () . Therefore, if you want to get the value for field 5, you can use something like this

 var field_five = jQuery('#input_2_5').val(); 

The input identifier follows the naming convention input_ {form_id} _ {field_id}, and for fields with multiple inputs, they end with _ {input_no}. You can confirm what the input identifier is by checking the box using the browser developer tools, where you will see something like this.

 <li id="field_2_5" class="gfield"> <label class="gfield_label" for="input_2_5">Number</label> <div class="ginput_container"> <input name="input_5" id="input_2_5" type="text" value="" class="medium" tabindex="5"> </div> </li> 

To use the resulting value in the calculation, the script would look like this:

 <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> 
+2
source share

All Articles