• Resolved KaraDesigns

    (@chynee)


    I hope I can explain this. I have field with 4 radio buttons. Each radio button can generate 3 different equations. And then each equation would need a dependency based on:

    – If value is less than 1001
    – If value is greater than 1000 & If value is less than 2001
    – If value is greater than 2000

    In order to create this, would I have to do a different Calculated Field for each equation (which would end up being 12 Calculated Fields)?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter KaraDesigns

    (@chynee)

    Ok. I think I figured it out and I came up with this code:

    (function(){
    if(fieldname3 == 1 Week > 1001) return 0.04*fieldname7;
    if(fieldname3 == 1 Week < 1000 && >2001) return 0.05*fieldname7;
    if(fieldname3 == 1 Week < 2000) return 0.06*fieldname7;
    })();

    I tried entering it in the “Set Equation” section of the Calculate Field control. But the code doesnt work. Can you tell me where I went wrong?

    Plugin Author codepeople

    (@codepeople)

    Hello @chynee

    I don’t know who is Week in the equation, So, I’ll assume it is a global javascript variable, and that is correct. In this case, the correct equation’s structure would be:

    
    (function(){
        if(fieldname3 == 1 && 1000 <= Week) return 0.04*fieldname7;
        if(fieldname3 == 1 && 1000 < Week && Week <= 2000) return 0.05*fieldname7;
        if(fieldname3 == 1 && 2000 < Week) return 0.06*fieldname7;
    })();
    

    Please, note you can nesting if conditional statements. The previous equation can be optimized as follows:

    
    (function(){
        if(fieldname3 == 1){
            if(1000 <= Week) return 0.04*fieldname7;
            if(1000 < Week && Week <= 2000) return 0.05*fieldname7;
            return 0.06*fieldname7;
        }
    })();
    

    Best regards.

    Thread Starter KaraDesigns

    (@chynee)

    “1 Week” is the title of one of the radio buttons. Is that how it works? I would insert the name of the radio button after “fieldname3 ==” ???

    Plugin Author codepeople

    (@codepeople)

    Hello @chynee

    I’m sorry, but I don’t understand what do you want to implement. Please, send me the link to the page where the form is inserted and describe the equation.

    Best regards.

    Thread Starter KaraDesigns

    (@chynee)

    Hi,

    Thanks for replying quickly. The form is here: https://topscholarsediting.com/?cff-form=6

    I only started working on the “Editing & Proofreading” dropdown. When you select “1 Week” under the Turnaround Time section, I would like the TOTAL to come up as: Enter Word Count Number x 0.04

    Hope that makes sense.

    Plugin Author codepeople

    (@codepeople)

    Hello @chynee

    I guess you are referring to an equation similar to the following one:

    
    (function(){
    	if(fieldname2 == 'Editing & Proofreading')
    	{
    		if(fieldname3 == '1 Week') return 0.04 * fieldname7;
    		if(fieldname3 == '3 Days') return 0.05 * fieldname7;
    		if(fieldname3 == '2 Days') return 0.06 * fieldname7;
    		if(fieldname3 == '24 Hrs (RUSH)') return 0.09 * fieldname7;
    	}
    })()
    

    Best regards.

    Thread Starter KaraDesigns

    (@chynee)

    What if I wanted to add this dependency:
    “If value is less than 1000”

    To this script:
    if(fieldname3 == ‘1 Week’) return 0.04 * fieldname

    How would it look?

    Plugin Author codepeople

    (@codepeople)

    Hello @chynee

    I’m sorry, but you are not being clear. Do you want check the number or words? If it is the case, you can edit the equation as follows:

    
    (function(){
    	if(fieldname2 == 'Editing & Proofreading' && fieldname3 == '1 Week')
    	{
    		if(fieldname7 < 1000) return 0.04 * fieldname7;
    		if(fieldname7 < 2000) return 0.05 * fieldname7;
    		return 0.06 * fieldname7;
    	}
    })()
    

    Now, you should include the other conditions.

    Best regards.

    Thread Starter KaraDesigns

    (@chynee)

    So sorry if I am not explaining it properly. But you definitely got what I am trying to say. Thank you so much!

    There’s 1 last thing (I hope). I need the number to round to only 2 decimals. I’ve added “PREC” in the code below, however, its still not showing me the 2 decimals:

    (function(){
    if(fieldname2 == ‘Editing & Proofreading’ && fieldname3 == ‘1 Week’)
    {
    if(fieldname7 < 1000) return PREC(0.04 * fieldname7);
    if(fieldname7 < 2000) return PREC(0.05 * fieldname7);
    return PREC(0.06 * fieldname7);
    }
    })()

    Plugin Author codepeople

    (@codepeople)

    Hello @chynee

    The PREC operation requires two parameters where the second parameter is the number of decimals, like: PREC(0.04 * fieldname7, 2)

    However, I recommend you to apply it only once, as follows:

    
    PREC((function(){
    	if(fieldname2 == 'Editing & Proofreading' && fieldname3 == '1 Week')
    	{
    		if(fieldname7 < 1000) return 0.04 * fieldname7;
    		if(fieldname7 < 2000) return 0.05 * fieldname7;
    		return 0.06 * fieldname7;
    	}
    })(), 2)
    

    Best regards.

    Thread Starter KaraDesigns

    (@chynee)

    WOW! Thank you so much. You rock!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Is it possible to set equations with multiple dependencies?’ is closed to new replies.