Title: conditional logic with dropdown
Last modified: June 23, 2022

---

# conditional logic with dropdown

 *  Resolved [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * (@borgesleti)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-with-dropdown/)
 * Hello, I need help with the dropdown fields.
    i’m trying to make a conditional
   function when an option from my list is checked. I’m calculating a weighted average.
 * I would like to know if it is possible to set weights for each dropdwon field
   of my form and add these values, and if it is also possible to put an option 
   in the dropdwon of not adding the weight of this field to the calculation.

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

 *  Thread Starter [borgesleti](https://wordpress.org/support/users/borgesleti/)
 * (@borgesleti)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-with-dropdown/#post-15766010)
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-with-dropdown/#post-15766064)
 * Hello [@borgesleti](https://wordpress.org/support/users/borgesleti/)
 * Thank you very much for using our plugin.
 * I’ll try to describe the process with a hypothetical example.
 * Assuming you have three dropdown fields fieldname1, fieldname2, and fieldname3.
 * Please, enter numbers only as the choices values, and the text you prefer as 
   their texts. For the “no adding weight” options, enter the number zero as their
   values.
 * Now, you can insert a calculated field in the form and enter the following equation:
 *     ```
       (function(){
           var weights = [fieldname1, fieldname2, fieldname3], 
               n = 0, 
               total=0;
   
           for(var i in weights)
           {
               if(weights[i]){n++;total+=weights[i];}
           }
   
           return total/n;
       })()
       ```
   
 * Best regards.

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

The topic ‘conditional logic with dropdown’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [3 years, 11 months ago](https://wordpress.org/support/topic/conditional-logic-with-dropdown/#post-15766064)
 * Status: resolved