• Resolved princeofabyss

    (@princeofabyss)


    Hi,

    I am implementing a Body Mass Index calculator with your plugin. So, the user enters his weight and height and it calculates an index, i.e. 22.56 or 31.28 etc. Up to here I’m fine.

    The other part of the BMI calculator is to display a label depending on the index returned. So, for instance, if the index is less than 18.5 it should display a predefined text with a title Underweight. If the index is in the range of 18.5 to 25 it should display another predefined text with the title Normal, etc… How could I implement this?

    I tried with the Instruct. Text element, and created all 6 categories, but I can’t find a way to make one of them at each calculation appear.

    Please give me some advice.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    You simply should use conditional statements as part of the equation to return the text corresponding to the result of the mathematics operations:

    For example, if the current equation is: fieldname1*fieldname2, and you want to return as result the text:

    “Text A” if the result is between 0 and 10,
    “Text B” if the result is between 10 and 20,
    “Text C” if the result is greater than 20

    The equation should be edited as follows:

    (function(){
    var v = fieldname1*fieldname2;
    if(v <= 10) return 'Text A';
    if(10 < v && v <= 20) return 'Text B';
    if(20 < v ) return 'Text C';
    })()

    If you need additional help implementing your project, I can offer you a custom coding service from my private website:

    https://cff.dwbooster.com/customization

    Best regards.

    Thread Starter princeofabyss

    (@princeofabyss)

    What are the Text A, B and C? I mean, are they three elements I drag into the form? And what elements they? Or, are they dynamically created in the Equation parameter?

    And one more question, it would be ideal to prepare all six elements styled with the appropriate colors to them, etc, and assign to them another hidden class in the Add Css layout keyword.

    Then upon calculation of the index, it would simply remove the hidden class from the respective element so that it gets displayed. But I guess the conditional dependencies aren’t designed to assign/remove css properties from elements, are they?

    Plugin Author codepeople

    (@codepeople)

    Hello,

    In my previous example, the texts are displayed in the calculated field as result of the equation, but if you want to display them using “Instruct. Text” fields to apply some styles, you should use dependencies, for example, if the fields with the texts are:

    For the “Text A”, the fieldname4
    For the “Text B”, the fieldname5
    For the “Text C”, the fieldname6

    The equation would be the original one: fieldname1*fieldname2 and then, define the conditional rules in the dependencies section of the calculated field, similar to the screenshot in the following link:

    https://wordpress.dwbooster.com/customdownloads/2017-03-03/screenshot.jpg

    Best regards.

    Thread Starter princeofabyss

    (@princeofabyss)

    Arghhhh, you can’t imagine what happened…

    That was exactly what I did in the first place, but because of my locale, we use “,” for the decimal point and “.” for the thousands separator.

    So, foolishly I used numbers like 18,5 to 25,5 to define the limits. And because it didn’t work, I thought it was a wrong approach and rejected it altogether.

    But since you confirmed this is the way, I finally realized that “,” was probably the issue. So I tried it, and indeed it works great.

    Thanks a lot for your support! Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show additional text depending on result’ is closed to new replies.