Title: Dropdown Box Problems. Incorrect Format?
Last modified: January 25, 2018

---

# Dropdown Box Problems. Incorrect Format?

 *  Resolved [torqueing](https://wordpress.org/support/users/torqueing/)
 * (@torqueing)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/)
 * I’m trying to replicate a calculation from Excel and I cant seem to get it to
   work. I’m pretty sure I’m missing something from the logical operators. The field
   looks like this:
    `IF((fieldname8, SP) * AND((fieldname7 > 2879.17)) , 2879.17,
   IF((fieldname8, SP) * AND(fieldname7, < 2879.17) , fieldname7 , IF(fieldname8,
   MP) * (AND(fieldname7 > 3629.17 , fieldname7) , 3629.17 , fieldname7)))`
 * Fieldname8 is a dropdown box with just 2 options: SP and MP, each with a number
   value.
 * The Excel equation looks like this: `=IF((B17="SP")*AND(B14>2879.17),2879.17,
   IF((B17="SP")*AND(B14<2879.17),B14,IF((B17="MP")*AND(B14>3629.17,B14),3629.17,
   B14)))`
    Obviously B17 is fieldname7 and B14 is fieldname8 (a number)
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdropdown-box-problems-incorrect-format%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/#post-9901602)
 * Hello [@torqueing](https://wordpress.org/support/users/torqueing/),
 * Our plugin is not Excel, and you cannot use the same structures. For example,
   you cannot compare the fieldname8 with the choices’ texts, in the equations only
   are used the values. So, the correct equation would be:
 *     ```
       (function(){
       if(fieldname8 == 2879.17 && 2879.17 < fieldname7) return 2879.17;
       if(fieldname8 == 2879.17 && fieldname7 < 2879.17) return fieldname7;
       if(fieldname8 == 3629.17 && 3629.17 < fieldname7) return 3629.17;
       return fieldname7;
       })()
       ```
   
 * If you prefer to use the “IF” and “AND” operations distributed with the plugin,
   the equation would be:
 *     ```
       IF(AND(fieldname8 == 2879.17, 2879.17 < fieldname7), 2879.17, IF(AND(fieldname8 == 2879.17, fieldname7 < 2879.17), fieldname7, IF(AND(fieldname8 == 3629.17 && 3629.17 < fieldname7), 3629.17,fieldname7)))
       ```
   
 * Actually, I prefer a more optimized implementation, all your equation is reduced
   to:
 *     ```
       MIN(fieldname8,fieldname7)
       ```
   
 * Best regards.
 *  Thread Starter [torqueing](https://wordpress.org/support/users/torqueing/)
 * (@torqueing)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/#post-9902682)
 * Thankyou. You, my good man, are a genius 🙂
 * If I could give you more than 5 stars I would
 *  Thread Starter [torqueing](https://wordpress.org/support/users/torqueing/)
 * (@torqueing)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/#post-9906106)
 * Although I’m having a different problem I think it’s in the same ballpark wrt
   syntax.
 * This just doesn’t seem to work:
 *     ```
       (function(){
       if(fieldname7 < 1083.30) return 0 ;
       } 
       else if(fieldname7 > 1083.30 && fieldname7 < 1614.33) { 
       1001 * 0.005 + fieldname7 -1001 *002 ;
       }
       else { return 7 ;
       })()
       ```
   
    -  This reply was modified 8 years, 4 months ago by [torqueing](https://wordpress.org/support/users/torqueing/).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/#post-9906162)
 * Hello [@torqueing](https://wordpress.org/support/users/torqueing/),
 * The number of symbols: “{” and “}” is incorrect, furthermore you are not using
   the “return” statements as should. The correct one is:
 *     ```
       (function(){
       if(fieldname7 < 1083.30){ return 0 ;}
       else if(1083.30 <= fieldname7 && fieldname7 < 1614.33) { return 1001*0.005+fieldname7-1001*002 ;}
       else { return 7;}
       })()
       ```
   
 * or simply:
 *     ```
       (function(){
       if(fieldname7 < 1083.30) return 0 ;
       if(1083.30 <= fieldname7 && fieldname7 < 1614.33) return 1001*0.005+fieldname7-1001*002;
       return 7;
       })()
       ```
   
 * Best regards.
 *  Thread Starter [torqueing](https://wordpress.org/support/users/torqueing/)
 * (@torqueing)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/#post-9906199)
 * Thanks again. I’ve never learned javascript so I’m trying to learn it through
   your examples and this on w3c schools
 *     ```
       if (time < 10) {
           greeting = "Good morning";
       } else if (time < 20) {
           greeting = "Good day";
       } else {
           greeting = "Good evening";
       }
       ```
   
 * hahaha 🙂
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/#post-9906265)
 * Hello,
 * Yes, but into a function structure you should use the “return” statement to return
   the result, for example, assuming that in your piece of code the time variable
   corresponds to the fieldname1 field, the equation would be:
 *     ```
       (function(){
       var greeting = "Good evening";
       if (fieldname1 < 10) {
           greeting = "Good morning";
       } else if (fieldname1 < 20) {
           greeting = "Good day";
       }
       return greeting;
       })()
       ```
   
 * As you can see the equation is even simpler than the original code because the
   last “else” is unnecessary.
 * Best regards.

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

The topic ‘Dropdown Box Problems. Incorrect Format?’ 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

 * [dropdown box](https://wordpress.org/support/topic-tag/dropdown-box/)
 * [operators](https://wordpress.org/support/topic-tag/operators/)

 * 6 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/dropdown-box-problems-incorrect-format/#post-9906265)
 * Status: resolved