• Resolved ramanandmehta

    (@ramanandmehta)


    Hi sir, Im creating a simple bmr calculator in which I have two radio button fields for equation and gender selections.
    I am using this code in formula but its not working.

    (function(){
    if (fieldname56 === "Miffin St Jeor") {
    if (fieldname3 === "Male") {
    return (9.99 * fieldname30) + (6.25 * fieldname31) - (4.92 * fieldname2) + 5;
    } else if (fieldname3 === "Female") {
    return (9.99 * fieldname30) + (6.25 * fieldname31) - (4.92 * fieldname2) - 161;
    }
    } else if (fieldname56 === "Harris Benedict Equation (Revised)") {
    if (fieldname3 === "Male") {
    return 88.362 + (13.397 * fieldname30) + (4.799 * fieldname31) - (5.677 * fieldname2);
    } else if (fieldname3 === "Female") {
    return 447.593 + (9.247 * fieldname30) + (3.098 * fieldname31) - (4.33 * fieldname2);
    }
    }
    return 0; // Return 0 if the conditions are not met
    })();

    Please guide me, thanks.

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

    (@codepeople)

    Hello @ramanandmehta

    Please don’t use single line comments in the equations:

    // Return 0 if the conditions are not met

    The plugin tries to minify the equations code and the single-line comments structure could make this process fail. Use block comment structure instead:

    /* Return 0 if the conditions are not met */

    The rest of the code in the equation seems correct, but I would need the link to the page containing the form because I cannot check from the code in your entry if the fields’ values used for comparing are correct.

    Best regards.

    Thread Starter ramanandmehta

    (@ramanandmehta)

    Salute for the faster response; I have never seen before.

    I have removed the comment but it’s not working. here is test page

    • This reply was modified 1 year, 10 months ago by ramanandmehta.
    Plugin Author codepeople

    (@codepeople)

    Hello @ramanandmehta

    Thank you very much for the link. The issue is caused by your form structure and fields’ values. For example, in the gender field, you entered the choices’ texts but not their values. So, the value of the gender field will be the empty text. The equations use the choices’ values, please enter them.

    The “Formula” field has an additional problem, you left its choices’ values empty and configured it as dependent on the “Show Advance setting” field. So, when the “Show Advance setting” is unticked, the “Formula” field value will be empty.

    So, the solution to your equation is:

    1. Enter all choices values, in the “Gender” and “Formula” fields.
    2. If you have configured the “Formula” field as dependent, you should implement the condition in the equation as follows:

    if (fieldname56 === "Miffin St Jeor") {
    /* Your code Here */
    } else {
    /* Your code Here */
    }

    In this case, the “else” code block would be evaluated if the fieldname56 choice selected is "Revised Harris-Benedict" or the field is deactivated by the dependency.

    Best regards.

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

The topic ‘Multiple condition for different equation’ is closed to new replies.