• Resolved jankiel7

    (@jankiel7)


    I would like to make a price check calculator, that will be calculate price depends on what option you choose, and with and DropDown there was no problem for me but with two I dont know how to make it this is my code idea:

    (function cena(){
    
    if(fieldname9 == "Tak") AND (fieldname11 == "Tak") return PREC((fieldname6*57)*1.1, 2);
    
    if(fieldname9 == "Tak") AND (fieldname11 == "NIE") return PREC((fieldname6*45)*1.1, 2);
    
    if(fieldname9 == "NIE") AND (fieldname11 == "Tak") return PREC((fieldname6*57), 2);
    
    else return PREC((fieldname6*45), 2);
    
    }
    
    )();
    
    

    It works like you pick Height and Weight then it calculate to m2 and then it depend what you choose Yes/No in to DropDowns it changes the price, but i have no idea how to make it work, beacuse it have to make choose from all possibility of choose YES/YES Yes/NO NO/YES and No/No

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

    (@codepeople)

    Hello @jankiel7

    First, in javascript the logical operator that represents the AND is the double symbol &&

    Second, in javascript the group of conditions into the if conditional statement must be enclose into parenthesis.

    Third, the function’s name is unnecessary in the equation.

    So, the equation would be similar to:

    
    (function(){
    
        if(fieldname9 == "Tak" && fieldname11 == "Tak") 
            return PREC(fieldname6*57*1.1, 2);
    
        if(fieldname9 == "Tak" && fieldname11 == "NIE") 
            return PREC(fieldname6*45*1.1, 2);
    
         if(fieldname9 == "NIE" && fieldname11 == "Tak") 
            return PREC(fieldname6*57, 2);
    
        return PREC(fieldname6*45, 2);
    }
    
    )();
    

    Note that I’ve removed some unnecessary parenthesis and instructions.

    Best regards.

    Thread Starter jankiel7

    (@jankiel7)

    Thank you for the answer, i tried your code and it calculted only first IF when two option YES/YES are choosen, others option doesnt work

    Plugin Author codepeople

    (@codepeople)

    Hello @jankiel7

    Please, indicate the link to the page where the form is inserted. I simply have modified your initial equation, trusting that the data are correct.

    Best regards.

    Thread Starter jankiel7

    (@jankiel7)

    https://tureklamy.pl/testtesttestowy/

    Here is the link for the calculator, greetings.

    Plugin Author codepeople

    (@codepeople)

    Hello @jankiel7

    The issue is simple. Javascript is a case sensitive language. In the equation you are comparing with NIE, but the field value is Nie, and for javascript this comparison: "Nie" == "NIE" returns false. So, you should edit the fields values or the equation.

    Best regards.

    I want to return calculated value from fielname2. Pls correct below code.

    (function(){
    if(fieldname1 = ‘hb’) return calculated value from fieldname2;
    })();

    Any suggestions would be greatly appreciated.

    Habib

    Plugin Author codepeople

    (@codepeople)

    Hello @habib0030

    In javascript the operator for equality is the double symbol: == because the symbol: = is used for assignment. So, the equation would be:

    
    (function(){
    if(fieldname1 == 'hb') return fieldname2;
    })();
    

    or simply:

    
    IF(fieldname1=='hb', fieldname2, '')
    

    Best regards.

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

The topic ‘Multiple IF function with DropDown forms’ is closed to new replies.