Title: Values in a range
Last modified: November 26, 2019

---

# Values in a range

 *  Resolved [mftzk](https://wordpress.org/support/users/mftzk/)
 * (@mftzk)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/values-in-a-range-2/)
 * I’ve been struggling with my size calculator, I can never make all the fields
   work properly… This is the code I used at the first field not working (“Your 
   Underbust Size”):
 * (function(){
    if(62,1 <= fieldname2 <= 67) return ’38’; if(67,1 <= fieldname2
   <= 72) return ’40’; if(72,1 <= fieldname2 <= 77) return ’42’; if(77,1 <= fieldname2
   <= 82) return ’44’; if(82,1 <= fieldname2 <= 87) return ’46’; if(87,1 <= fieldname2
   <= 92) return ’48’; })()
 * I’ve tried lots of other variations that didn’t work, but this code is what made
   the most sense to me. If you could help me make it work, I’d be really grateful.
   This is an amazing plugin, thanks already!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fvalues-in-a-range-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/values-in-a-range-2/#post-12178173)
 * Hello [@mftzk](https://wordpress.org/support/users/mftzk/)
 * Your equation includes some errors:
 * – First, in javascript the decimal separator is point “.” and not the comma “,”
 * – Second, if you want know if a variable, or field in your case, is into an interval,
   the correct would be the use of the “and” operator (represented in javascript
   by the double symbol: `&&`) as follows:
 *     ```
       if(62.1 <= fieldname2 && fieldname2 <= 67) return 38;
       ```
   
 * – Third, note your equation is not considering values like: 67.01, 67.02, …..
   and the same for the other comparisons: 72.01, 72.02, ……
 * The correct equation would be:
 *     ```
       (function(){
       if(62 < fieldname2 && fieldname2 <= 67) return 38;
       if(67 < fieldname2 && fieldname2 <= 72) return 40;
       if(72 < fieldname2 && fieldname2 <= 77) return 42;
       if(77 < fieldname2 && fieldname2 <= 82) return 44;
       if(82 < fieldname2 && fieldname2 <= 87) return 46;
       if(87 < fieldname2 && fieldname2 <= 92) return 48;
       })()
       ```
   
 * Best regards.
 *  Thread Starter [mftzk](https://wordpress.org/support/users/mftzk/)
 * (@mftzk)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/values-in-a-range-2/#post-12186306)
 * It worked out in the “underbust” field, but I don’t know why it’s not working
   again in the “cup size” field (which is the fieldname22) with this code:
 * (function(){
    if(8 < fieldname23 && fieldname23 <= 10) return AAA; if(10 < fieldname23&&
   fieldname23 <= 12) return AA; if(12 < fieldname23 && fieldname23 <= 14) return
   A; if(14 < fieldname23 && fieldname23 <= 16) return B; if(16 < fieldname23 &&
   fieldname23 <= 18) return C; if(18 < fieldname23 && fieldname23 <= 20) return
   D; })()
 * I replaced the code you sent with the values I needed in that field, but it’s
   not showing up…
 * “fieldname23” calculates the difference between bust and underbust, although 
   it could also be replaced with the operation “fieldname3-fieldname2”, but I don’t
   know how to do it, so I put this extra field to calculate it.
 * I tried doing the whole operation with the code below, based on the one you sent
   too, but honestly I know absolutely nothing about javascript. I was trying to
   build a code out of the other topics answers, but nothing I do seems to work 
   out:
 * (function(){
    if(8 < (fieldname3-fieldname2) && (fieldname3-fieldname2) <= 10)
   return AAA; if(10 < (fieldname3-fieldname2) && (fieldname3-fieldname2) <= 12)
   return AA; if(12 < (fieldname3-fieldname2) && (fieldname3-fieldname2) <= 14) 
   return A; if(14 < (fieldname3-fieldname2) &&(fieldname3-fieldname2) <= 16) return
   B; if(16 < (fieldname3-fieldname2) && (fieldname3-fieldname2) <= 18) return C;
   if(18 < (fieldname3-fieldname2) && (fieldname3-fieldname2) <= 20) return D; })()
 * After that, all I need is to show the result of “underbust size” and “cup size”
   together, one after another. For exemple, if you enter these values:
 * Underbust Measurement: 73
 * Bust Measurement: 80
 * You will have “Your Underbust Size” showing the number 42, and the “Your Cup 
   Size” should be displaying the size AAA. In the field “Your Final Size” I’d like
   to display the whole size, which would be 42AAA.
 * Thank you for the fast reply!
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/values-in-a-range-2/#post-12186318)
 * Hello [@mftzk](https://wordpress.org/support/users/mftzk/)
 * The issue is simple, in javascript the texts, or textual values, must be enclosed
   between single or double quotes, so, the correct equation would be:
 *     ```
       (function(){
       var v = fieldname3-fieldname2;	
       if(8 < v && v <= 10) return 'AAA';
       if(10 < v && v <= 12) return 'AA';
       if(12 < v && v <= 14) return 'A';
       if(14 < v &&v <= 16) return 'B';
       if(16 < v && v <= 18) return 'C';
       if(18 < v && v <= 20) return 'D';
       })()
       ```
   
 * Note in the previous equation I’ve defined the variable v with the result of 
   the mathematical operation to not repeat it so many times, improving the equation’s
   performance. Furthermore, note your equation is excluding all results lesser 
   than or equal to 8 and greater than 20.
 * Best regards.
 *  Thread Starter [mftzk](https://wordpress.org/support/users/mftzk/)
 * (@mftzk)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/values-in-a-range-2/#post-12205353)
 * It’s working now! Thank you very much, great support always.

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

The topic ‘Values in a range’ 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

 * [range](https://wordpress.org/support/topic-tag/range/)
 * [value](https://wordpress.org/support/topic-tag/value/)

 * 4 replies
 * 2 participants
 * Last reply from: [mftzk](https://wordpress.org/support/users/mftzk/)
 * Last activity: [6 years, 5 months ago](https://wordpress.org/support/topic/values-in-a-range-2/#post-12205353)
 * Status: resolved