• Resolved justin_19

    (@justinsmith19)


    Hi @codepeople,

    I am trying to create a function for a calculated field (fieldname3), which looks like this:

    (function(){
    
    if(fieldname1 = 100) return (fieldname2*1);
    if(fieldname1 = 200) return (fieldname2*2);
    if(fieldname1 = 300) return (fieldname2*3);
    if(fieldname1 = 400) return (fieldname2*5);
    if(fieldname1 = 500) return (fieldname2*6);
    
    })()

    fieldname1 is a slider from 100 to 4000 in steps of 100
    fieldname2 is also a slider from 1 to 30 in steps of 1

    fieldname3 is a calculated field with the above function that does not seem to be working, the calculated field is simply blank.

    I am not sure what I am doing wrong.

    I’d appreciate your assistance.
    Thanks

    The page I need help with: [log in to see the link]

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

    (@codepeople)

    Hello @justinsmith19

    In javascript, the operator for equality is the double symbol ==, because, the symbol = is used for assignment. So, your equation can be implemented as follows:

    
    (function(){
    
    if(fieldname1 == 100) return fieldname2*1;
    if(fieldname1 == 200) return fieldname2*2;
    if(fieldname1 == 300) return fieldname2*3;
    if(fieldname1 == 400) return fieldname2*4;
    if(fieldname1 == 500) return fieldname2*5;
    
    })()
    

    By the way, I think the equation can be optimized as follows:

    
    fieldname1/100*fieldname2
    

    And wouldn’t be needed the conditional statements.

    Best regards.

    Thread Starter justin_19

    (@justinsmith19)

    Hi @codepeople,

    Apologies, that was a silly mistake.

    Thanks so much for your help.

    Regards

    How to hide the initial value of Calculated Cost.
    ROUND(fieldname2*fieldname3*fieldname4/1728*fieldname5+fieldname6+200,100)

    1. I have a pre-choice in dropdown of $100 in filedname6

    2. I have added a hidden value +200

    The Calculated Cost showed $300 already. I wanted to hide this until they have selected all.

    Plugin Author codepeople

    (@codepeople)

    Hello @traveler305

    If you don’t want to evaluate the mathematical operations until the user selects a choice in the fieldname6 field, you can edit the equation as follows:

    
    IF(fieldname6, ROUND(fieldname2*fieldname3*fieldname4/1728*fieldname5+fieldname6+200,100), '')
    

    Best regards.

    Thank you so much for your very prompt reply. The formula works great!

    One last question, say the total is “4215”, and I want to round this to “4300” although the round off for this number is 4200, what will I add to the equation?

    IF(fieldname6, ROUND(fieldname2*fieldname3*fieldname4/1728*fieldname5+fieldname6+200,100), ”)

    Best regards.

    Plugin Author codepeople

    (@codepeople)

    Hello @traveler305

    Use the CEIL operation instead of the ROUND one.

    Please, read the following post in the plugin’s blog:

    https://cff.dwbooster.com/blog/2020/09/20/rounding-numbers/

    Best regards.

    Thank you so much and it now worked as desired.

    Again, please accept my utmost thanks for your very prompt support.

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘blank calculated field’ is closed to new replies.