10 Replies Latest reply on Jan 8, 2014 11:32 AM by Since 1914

# Need help with Custom Calculation

Hello,

I have created a pdf form so customers can order items.  Simple calculations for quantity times price and subtotal are done.  The problem I am having is with the Handling Fee calculation.  We charge 5% of the Subtotal amount,with a minimum charge of \$5.00.  I need a javascript that will automatically calculate this.  Can anyone please help?   Thank you.

• ###### 1. Re: Need help with Custom Calculation

You can use something like this as the custom calculation code of the handling fee field:

var subtotal = Number(this.getField("Subtotal").value);

if (subtotal==0) event.value = 0;

else {

var fee = subtotal * 0.05;

if (fee<5) fee = 5;

event.value = fee;

}

• ###### 2. Re: Need help with Custom Calculation

Thanks.  I copied and pasted your script, but for some reason the handling fee is not being calculated correctly.

• ###### 3. Re: Need help with Custom Calculation

In what way, exactly?

• ###### 4. Re: Need help with Custom Calculation

Try the following script in the custom calculation for the fee amount field.

function GetField(cFieldName) {
console.println("GetField");
// return field object for named field;
var oField = this.getField(cFieldName);
if(oField == null) app.alert("Error accessing field named " + cFieldName, 0, 0);
return oField;
}

var cSubtotalField = "Subtotal"; // name for subtotal field;
var oSubtotal = GetField(cSubtotalField); // get field object;
var nSubtotal = Number(oSubtotal.value); // get value of subtotal field object;

var nFee = nSubtotal * 0.05; //compute tentative fee;
nFee = Math.max(5, nFee); // minimum fee 5 or computed value;
event.value = nFee;

It will report if you are using a different name or have  a nane error for the input field name.

• ###### 5. Re: Need help with Custom Calculation

The \$5.00 minimum fee worked, but the percentage would calculate wrong i.e. a subtotal of \$336.00 calculated a handling fee of \$10.80.  It should be \$16.80.

• ###### 6. Re: Need help with Custom Calculation

This works as long as all of the fields are completed i.e. entering '0' if not ordering an item.  I would need to make all quantity fields mandatory.  Is there a way to get around this?  I really appreciate all of your help!!!