10 Replies Latest reply on Aug 29, 2014 8:25 AM by Maronberg

# Calculation Help

Good Morning All,

I have a form in which users type values into fields and at the bottom, the form automatically adds all of the amounts to show the "Total Monthly" value. Then, underneath, I have a field that multiplies the "Total Monthly" value by 12 to show the "Total Annually". My issue is that when nothing is typed in the form at all, these two fields have the value of "\$0.00". I want to make it so that they are blank until someone types something into the form. I have attached two screenshots to show you what I am talking about. Thank you for your help in advance.

• ###### 1. Re: Calculation Help

Use this code as their custom validation script:

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

• ###### 2. Re: Calculation Help

Sorry, I am a complete noob when it comes to coding. How do I do the multiplication as well?

• ###### 3. Re: Calculation Help

It has nothing to do with each other. For the calculation enter this

(EXACTLY) as the Simple Field Notation option under the Calculate tab:

Total\ Monthly * 12

• ###### 4. Re: Calculation Help

Correct, I had that as my original script, except it leaves the \$0.00" there when nothing is typed in.

• ###### 5. Re: Calculation Help

So what are you asking me, exactly?

• ###### 6. Re: Calculation Help

I need a script that would take the value from the "Total Monthly" field with the dollar sign(that field automatically generates the sum from the above fields) and multiply it by "12" but also is blank when the there is nothing in the "Total Monthly" field.

• ###### 7. Re: Calculation Help

So I have this script(see below) in another form. Instead of subtraction, I want it to multiply "Rent_20" by 12.

var res = +this.getField("Rent_20").value - +this.getField("TotalAnnualExpenses0").value;

if (res != 0) {

event.value = res;

}

else {

event.value = "";

}

• ###### 8. Re: Calculation Help

If the result of a calculation has a currency symbol or a percentage symbol the custom formatting script will not work. You need a script to convert the formatting back to a numeric value with no currency symbol of percentage symbol.

var nDec = 2; // number of decimal places to display

var sepStyle = 0; // style for thousand and decimal separators;

var negStyle = 0; // style to display negative numbers;

var currencySymbol = "\$"; // currency symbol to use;

var currencyPrepend = true; // pre-pend the currency symbol

if(event.value == 0) {

// value is zero;

event.value = ""; // set value to null string;

currencySymbol = ""; // set currency symbol to none;

AFNumber_Format(nDec, sepStyle, negStyle, "", currencySymbol, currencyPrepend); // format result;

} else {

// non-zero value, format as variables are set;

AFNumber_Format(nDec, sepStyle, negStyle, "", currencySymbol, currencyPrepend);

}

• ###### 9. Re: Calculation Help

The currency symbol is only part of the template, not the actual form. See the attached pic. Sorry for being so confusing, I really appreciate your help.

• ###### 10. Re: Calculation Help

I actually figured it out. A lot simpler than I thought. Thank you, I wouldn't have got it without you. Below is the code I used.

var res = +this.getField("Rent_20").value * 12;

if (res != 0) {

event.value = res;

}

else {

event.value = "";

}