• Resolved rolbuk

    (@rolbuk)


    Hi,
    I have question on how to make shipping price calculation with radio button.
    fieldname1(Weight)
    fieldname2 radio button with 3 choice DHL, Fedex, UPS

    DHL and UPS has static price 2.99, but FEDEX has price based on weight. How can I make calculation depending on the user’s radio button choice?
    Thanks!

    • This topic was modified 4 years, 9 months ago by rolbuk.
Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    There is a simple solution. For example, assuming FEDEX includes a factor per kg (for example: $1.5), and fieldname1 is the weight in kg.

    First, enter as the values of choices in the Radio Buttons field (fieldname2): DHL, UPS and FEDEX, respectively.

    and then, implement the equation associated to the calculated field as follows:

    
    (function(){
    if(fieldname2=='FEDEX')) return fieldname1*1.5;
    return 2.99;
    })()
    

    or simply:

    
    IF(fieldname2=='FEDEX', fieldname1*1.5, 2.99)
    

    Best regards.

    Set your calculation at the radio buttons to UPS 2.99, DHL 2.99, e.g. Fedex 1.50.

    create a new field for “weight” which is only being displayed if the user chooses Fedex (dependency).

    insert the dependency “weight” in your DHL,UPS,Fedex field at the radio buttons field unter the fedex entry.

    set the range for values e.g. 1 to 30

    Create an additional calculation field which is displayed only if Fedex is chosen.

    You might want to see some calculation I just have created with radio buttons and lots of dependencies : https://www.roller-aus-blech.de/vespa-blog/drehzahlrechner/

    • This reply was modified 4 years, 9 months ago by martin136.
    Thread Starter rolbuk

    (@rolbuk)

    Thanks you both.
    Codepeople there is additional price which calculated like this
    if(fieldname1 <= 2) return 2.89;
    if(fieldname1 <= 3) return 3.39;
    if(fieldname1 <= 4) return 3.89;

    How can I connect these calculation? It should be something like this
    (function(){
    if(fieldname1 <= 2) return 2.89+(fieldname2==’FEDEX’);
    if(fieldname1 <= 3) return 3.39+(fieldname2==’FEDEX’);

    })()

    Plugin Author codepeople

    (@codepeople)

    Hello @rolbuk,

    The equation could be implemented as follows:

    
    (function(){
    if(fieldname2 != 'FEDEX') return 2.99;
    if(fieldname1 <= 2) return 2.89;
    if(fieldname1 <= 3) return 3.39;
    if(fieldname1 <= 4) return 3.89;
    })()
    

    and that’s all.

    Best regards.

    Thread Starter rolbuk

    (@rolbuk)

    @codepeople but it wouldn’t calculate both prices. I need formula which would show result of if(fieldname1 <= 2) return 2.89; + if(fieldname2 != ‘FEDEX’) return 2.99;
    We very close to right formula:)

    • This reply was modified 4 years, 9 months ago by rolbuk.
    Plugin Author codepeople

    (@codepeople)

    Hello @rolbuk

    I’m not totally sure of your equation’s description, but I guess you are referring to something like:

    
    (function(){
    var factor = IF(fieldname2 != 'FEDEX', 2.99, 0);
    if(fieldname1 <= 2) return 2.89+factor;
    if(fieldname1 <= 3) return 3.39+factor;
    if(fieldname1 <= 4) return 3.89+factor;
    })()
    

    Best regards.

    Thread Starter rolbuk

    (@rolbuk)

    Hi,
    I think I found the right calculation, but it doesn’t work, could you please tell what is wrong with this formula? Thanks.

    (function(){
    if((AND(fieldname11 == ‘Omniva’, fieldname2 <= 2) ) return 5.99; return 2.99;
    })()

    Actually it explain the flow if fieldname11 is Omniva and fieldname <=2 result 5.99, otherwise 2.99

    Plugin Author codepeople

    (@codepeople)

    Hello @rolbuk

    Your equation’s structure includes an extra open parenthesis into the conditional statement, furthermore the single quote symbols are invalid, but probably they where replaced by the text editor of this forum. The correct equation would be:

    
    (function(){
    if(AND(fieldname11 == 'Omniva', fieldname2 <= 2)) return 5.99; 
    return 2.99;
    })()
    

    Best regards.

    Thread Starter rolbuk

    (@rolbuk)

    Thanks @codepeople now it works. But the next formula with fieldname <= 2 does not show right result. Anything wrong with this formula?
    (function(){
    if(AND(fieldname11 == ‘Omniva’, fieldname2 <= 1))
    return 5.99;
    return 2.99;
    if(AND(fieldname11 == ‘Omniva’, fieldname2 <= 2))
    return 6.99;
    return 2.99;
    })()

    Plugin Author codepeople

    (@codepeople)

    Hello @rolbuk

    The “return” instruction moves the execution outside the equation, so, the “return” instruction that is not controlled by the conditional statements should be inserted at the end only, or the second conditional statement would not be reached.

    
    (function(){
    if(AND(fieldname11 == 'Omniva', fieldname2 <= 1)) return 5.99;
    if(AND(fieldname11 == 'Omniva', fieldname2 <= 2)) return 6.99;
    return 2.99;
    })()
    

    Best regards.

    Thread Starter rolbuk

    (@rolbuk)

    Okey, it works. The other problem is that above number 29, fieldname2 <= 30 return 8.99, otherwise 0.
    How can I implement it into my formula below? Thanks!

    (function(){
    if(AND(fieldname11 == ‘Omniva’, fieldname2 <= 1)) return 5.99;
    if(AND(fieldname11 == ‘Omniva’, fieldname2 <= 2)) return 6.99;
    return 2.99;
    })()

    • This reply was modified 4 years, 9 months ago by rolbuk.
    • This reply was modified 4 years, 9 months ago by rolbuk.
    • This reply was modified 4 years, 9 months ago by rolbuk.
    • This reply was modified 4 years, 9 months ago by rolbuk.
    Plugin Author codepeople

    (@codepeople)

    Hello @rolbuk

    I’m sorry, but I cannot implement the users’ projects (forms or formulas) as part of the support service. If you need that I implement your equations, you should request a custom coding service from my private website: Customization

    Best regards.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Radio button calculation’ is closed to new replies.