Title: Calculated field problem
Last modified: February 18, 2017

---

# Calculated field problem

 *  Resolved [jdar](https://wordpress.org/support/users/jdar/)
 * (@jdar)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/calculated-field-problem/)
 * I have two fields that need to talk one another, and I am stuck for a solution.
   
   [Link to calculator](http://www.robstreeremoval.com/quick-calculator/) (Click
   on **“Tree Removal with or without its stump ground”** then hit **Next**
 * Here is my problem:
    If the user inputs any number into the “Trunk circumference”
   field, then touches anything else in the form, it resets. Trunk circumference
   code: `(function(){ if(fieldname1 > 0) return prec(fieldname1*3.14,2); })();`
 * The value only stays if the “Or, Trunk diameter” field is filled in. I need the
   value of the “Trunk circumference” to stay, if the user DOES NOT type anything
   into the “Or, Trunk diameter” field.
 * My goal:
    Have the circumference calculated if the user enters in a diameter.
   If they don’t, then don’t do any calculations, and just use the inputted value
   of the circumference.
 * Help would be severely appreciated. Thank you

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/calculated-field-problem/#post-8819500)
 * Hello,
 * Please, modifies the equation associated to the fieldname7 as follows:
 *     ```
       (function(){
       var v7 = jQuery('[id*="fieldname'+'7_"]').val()*1;
       if(fieldname1 > 0 &&  v7 == 0) return prec(fieldname1*3.14,2);
       else return prec(v7,2);
       })()
       ```
   
 * Best regards.
 *  Thread Starter [jdar](https://wordpress.org/support/users/jdar/)
 * (@jdar)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/calculated-field-problem/#post-8822611)
 * You are truly an amazing individual! Thank you so much my friend!
    It works just
   as I need it to 🙂
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/calculated-field-problem/#post-8822790)
 * Hello,
 * In the next update of the plugin the process would be simpler, I’m implementing
   the use of the __ME__ constant.
 * In the current version of the plugin if you use directly the name of the calculated
   field that is being evaluated in its own equation, you would be creating an infinite
   loop.
 * For example, if you modify the equation as follows:
 *     ```
       (function(){
       if(fieldname1 > 0 &&  fieldname7 == 0) return prec(fieldname1*3.14,2);
       else fieldname7;
       })()
       ```
   
 * the equatio and form will fail because the fieldname7 is the calculated field
   that is being evaluated.
 * However, in the next version of the plugin you might use the constant __ME__ 
   and the process would be safety:
 *     ```
       (function(){
       if(fieldname1 > 0 &&  __ME__ == 0) return prec(fieldname1*3.14,2);
       else __ME__;
       })()
       ```
   
 * Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Calculated field problem’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

## Tags

 * [if statements](https://wordpress.org/support/topic-tag/if-statements/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)

 * 3 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/calculated-field-problem/#post-8822790)
 * Status: resolved