• Resolved namazee

    (@namazee)


    Hi,

    I would like to create calculated field that would display total pricing if customer select two countries from a dropdown list..

    Eg:

    Dropdown list 1 = customer selected Japan
    Dropdown list 2 = customer selected Canada

    the calculated field will display a specific value.

    Can i do it like this:
    IF(fieldname1 = “Japan” AND fieldname2 = “Canada”) return RM360.

    Please advice

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

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

    (@codepeople)

    Hello @namazee,

    There are some errors in your piece of code:

    First, in Javascript the operator for equality is the double symbol: “==” because the use of only one of them (=) represents the assignment.

    Second, in Javascript the operator that represent the “AND” is the double symbol: “&&” and the or “||”

    Third, Javascript is a case sensitive language, so, please, do not confuse the operation “IF” distributed with our plugin, with the conditional statement “if” in Javascript, they have different structures.

    Fourth, the texts must be close into single or double quotes: "RM360"

    Fifth, include the semicolon symbol at the end of a line of code that are not the symbols: {}

    Your code should be re-implemented as follows:

    
    (function(){
    if(fieldname1 == "Japan" && fieldname2 == "Canada") return "RM360";
    })()
    

    Best regards.

    Thread Starter namazee

    (@namazee)

    Hi sir,

    Can you please review if this code is correct? Because i cant get the output

    (function(){
    if(fieldname12 == “Guangzhou” && fieldname14 == “Kuala Lumpur” || “Selangor”) return “RM330”;
    if(fieldname12 == “Guangzhou” && fieldname14 == “Pulau Pinang” || “Melaka” || “Negeri Sembilan” || “Johor” || “Perak”) return “RM360”;
    if(fieldname12 == “Guangzhou” && fieldname14 == “Perlis” || “Kedah” || “Terengganu” || “Kelantan” || “Pahang” ) return “RM390”;
    if(fieldname12 == “Guangzhou” && fieldname14 == “Sabah”) return “RM480”;
    if(fieldname12 == “Guangzhou” && fieldname14 == “Sarawak”) return “RM550”;
    })()

    Only single like this is producing the output:

    (function(){
    if(fieldname1 == “Japan” && fieldname2 == “Canada”) return “RM360”;
    })()

    Plugin Author codepeople

    (@codepeople)

    Hello @namazee,

    There are some issues with your equation:

    First, in Javascript you should repeat the elements in every comparison:

    
    fieldname14 == "Kuala Lumpur" || fieldname14 == "Selangor"
    

    Second, in Javascript the “and” operator (&&) has more precedence than “or”, so, you should use parenthesis for grouping the “or” comparisons as follows:

    
    if(fieldname12 == "Guangzhou" && (fieldname14 == "Kuala Lumpur" || fieldname14 == "Selangor")) return "RM330";
    

    So, the equation would be:

    
    (function(){
        if(fieldname12 == "Guangzhou" && (fieldname14 == "Kuala Lumpur" || fieldname14 == "Selangor")) return "RM330";
        if(fieldname12 == "Guangzhou" && (fieldname14 == "Pulau Pinang" || fieldname14 == "Melaka" || fieldname14 == "Negeri Sembilan" || fieldname14 == "Johor" || fieldname14 == "Perak")) return "RM360";
        if(fieldname12 == "Guangzhou" && (fieldname14 == "Perlis" || fieldname14 == "Kedah" || fieldname14 == "Terengganu" || fieldname14 == "Kelantan" || fieldname14 == "Pahang")) return "RM390";
        if(fieldname12 == "Guangzhou" && fieldname14 == "Sabah") return "RM480";
        if(fieldname12 == "Guangzhou" && fieldname14 == "Sarawak") return "RM550";
    })()
    

    Or even better, nesting “if” conditional statements and using the “IN” operation distributed with the plugin:

    
    (function () {
    	if (fieldname12 == "Guangzhou")
    	{
    		if(IN(fieldname14,["Kuala Lumpur","Selangor"])) return "RM330";
    		else if(IN(fieldname14,["Pulau Pinang","Melaka","Negeri Sembilan","Johor","Perak"])) return "RM360";
    		else if(IN(fieldname14,["Perlis","Kedah","Terengganu","Kelantan","Pahang"])) return "RM390";
    		else if(fieldname14 == "Sabah") return "RM480";
    		else if(fieldname14 == "Sarawak") return "RM550";
    	}	
    })()
    

    More information in the following link:

    https://cff.dwbooster.com/documentation#conditions-module

    Best regards.

    Thread Starter namazee

    (@namazee)

    Hi sir,

    Unfortunately, after many attempts, the output still not showing anything (blank)

    Only this approach works:
    (function(){
    if(fieldname1 == “Japan” && fieldname2 == “Canada”) return “RM360”;
    })()

    Plugin Author codepeople

    (@codepeople)

    Hello,

    I’m no sure the form you are editing, but in this page there is not an equation with the structure of the equation in your tickets:

    https://factohub.namaxee.com/air-express/

    Best regards.

    Thread Starter namazee

    (@namazee)

    Plugin Author codepeople

    (@codepeople)

    Hello @namazee,

    I’ve tested your form and the equation has worked fine:

    Your current equation uses the fields: fieldname14 and fieldname12, the fieldname14 was defined as dependent of the fieldname6 field, specifically when the “Malaysia” choice is selected, and the fieldname12 was defined as dependent on the fieldname5, specifically when the “China” choice is selected. If you select any other choices in these fields (fieldname5 and fieldname6), the fieldname12 and fieldname14 are ignored and their values are considered as zero by the equations where they participate.

    I’ve selected the correct choices and the equation has been evaluated properly.

    Best regards.

    Thread Starter namazee

    (@namazee)

    Hi,

    To be honest, currently if i select guangzhou to perak, the output is still empty

    Thread Starter namazee

    (@namazee)

    Infact both those city resides in fieldname12 and fieldname14 respectively.

    Thread Starter namazee

    (@namazee)

    Hi there sir,

    It workeddd!!

    Thank you

    Plugin Author codepeople

    (@codepeople)

    Hello @namazee,

    Thank you very much for letting me know that your form is working properly.

    Best regards.

    Thread Starter namazee

    (@namazee)

    Hi sir,

    U helped me alot today,
    thank you so much,
    im purchasing the plugin first thing tomorrow.
    Need to get some sleep now, its 3.45am here in malaysia

    thanks again

    Thread Starter namazee

    (@namazee)

    Hi sir,

    Would like to get your response on this:

    Guangzhou China – West Malaysia (based on 12 states)
    First 3KG – RM51.00, additional weight RM16.00, sensitive goods add RM25.00 per invoice
    Minimum Weight – 3kg
    Maximum Weight – 35kg

    Rate – will be chosen based on actual weight (KG) or volumetric weight (H cm x W cm x D cm / 6000) whichever GREATER.
    Insert package dimension (Height cm x Width cm x Depth cm)
    Insert actual weight in KG
    Calculate #1 – (H cm x W cm x D cm / 6000)
    If volumetric weight is GREATER than actual weight, choose volumetric weight. (and vise versa)

    Based on the requirement, can i use the IF functions?

    Plugin Author codepeople

    (@codepeople)

    Hello @namazee,

    I’m sorry, but the support service does not cover the implementation of the users’ projects (forms or formulas). If you have a specific question would be a pleasure respond to it.

    By the way, if you need that I implement your project, do not hesitate in contact me through my private website:

    https://cff.dwbooster.com/customization

    Best regards.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘IF Statement’ is closed to new replies.