Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

  1.  
    I am looking to have users enter a guesstimated total $ and then create a calculator to display a estimated total delivery cost

    for values less than $100? total = $15

    for values $101 >= and <= $200 -----> ((entered value - 100) * 1.10) + 115

    for values >= $201 -----> ((entered value - 200 )* 1.05) + 225

    *** if outside coding must be done outside of what form assembly offers that is fine. I would just like to make this as painless as possible

    just need a little direction on the easiest way to make this happen

    Thanks

    Seth
    • CommentAuthordbuschho
    • CommentTimeJan 13th 2010
     
    Probably the easiest way is to create a custom function in the custom code block, like so:

    <script>
    function guessShipping(baseCost){

    var guessShipping = 0;

    if(baseCost <= 100){
    guessShipping = 15.00;
    }else if(baseCost >100 && baseCost <= 200){
    guessShipping = ((baseCost - 100)*1.10) + 115;
    }else{
    guessShipping = ((baseCost - 200)*1.05) + 225;
    }


    if( guessShipping < 15) // Sanity check, guessShipping should never be less than $15.00
    guessShipping = 15.00;


    return guessShipping;
    }
    </script>

    Now that've written the above, it's not the best way of doing this calculation, but it should work. Copy and paste that code into your custom code block, then go to your total cost field as make it as a variable, say "totalCost". then create a new field ( or go to your current guesstimate field ) and enter this as your formula:

    guessShipping(totalCost)

    It will not work in the formBuilder, but if you save and preview the form, it should work.

    Happy to help further,
    FA Support.
    • CommentAuthorlancegregg
    • CommentTimeJan 18th 2010
     
    being able to do this would save me a lot of time and redundant sections on my form, but i can't seem to figure it out based on what is above.

    If i have a drop down menu on my form with 3 options, and i make that question a variable "DropD" with values 1,2,3.
    I then want to check to see if DropD is greater than 1 so i can edit a different variable, "DiffV" to give a Total
    "DiffV"'s value would be based on a selection from another drop down menu
    What i want to do is if DropD > 1 then multiply DiffV by .25 else DiffV is the Total

    Would i enter my code as:

    <script>
    function Total(DropD)
    {
    var Total= 0;
    if(DropD> 1)
    {
    Total= DiffV * .25;
    }
    else
    {
    Total= DiffV;
    }
    return Total;
    }
    </script>

    And then, would i enter Total(DropD) as a formula in the field (Question) where i wanted to display the result?

    I have tried this but receive an error for the calculated field, but i'm not sure what i'm missing and if this should work i'll create a new form and start fresh with this fantastic new functionality

    TIA
    -Lance
    • CommentAuthordbuschho
    • CommentTimeJan 18th 2010
     
    Hello,

    I think the issue probably is that javascript doesnt know what you are referring to by DiffV. Make sure you marked DiffV as a variable (which you did no doubt) then change your function header to:
    function Total(DropD,DiffV)

    and call it as:
    Total(DropD,DiffV) in the formula.

    If that doesn't work, let me know and I'll take a look on the form. (which form?)
    • CommentAuthorlancegregg
    • CommentTimeJan 18th 2010
     
    adjusting the function header got it working.

    thanks very much for your quick response!

    -Lance
    • CommentAuthorlancegregg
    • CommentTimeJan 19th 2010
     
    Ok, i got one function working but i need to add two more, i've coded one thus far, but can't get it to work. It's below. It there any issue resulting from adding multiple scripts to the custom code section?

    <script>
    Function JerseyPrice(DiscPer,Fabric,Yth)
    {
    var JerseyPrice=0;
    if(DiscPer = 1)
    {
    JerseyPrice = Fabric*Yth*.85;
    }
    else if(DiscPer = 2)
    {
    JerseyPrice = Fabric*Yth*.80;
    }
    else if(DiscPer = 3)
    {
    JerseyPrice = Fabric*Yth*.75;
    }
    else
    {
    JerseyPrice = 0;
    }
    return JerseyPrice;
    }

    </script>

    thanks

    -Lance
    • CommentAuthordbuschho
    • CommentTimeJan 19th 2010
     
    in javascript the comparison operator is:
    ==
    not
    = (the assignment operator)

    so when you say:
    if( DiscPer = 1 )
    you are saying, " If you can assign the value one to the variable DiscPer, then do X "
    where as:
    if( DiscPer == 1 )
    you are saying, " If the variable DiscPer equals 1, then do X "

    also Function should be all lowercase.
    • CommentAuthorlancegregg
    • CommentTimeJan 19th 2010
     
    awesome, thanks again