Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- JavaScript Calculation> Value does not enter the f...

Community Beginner
,

Apr 18, 2020

Copy link to clipboard

Copied

Hi,

I have an adobe form in which I need to calculate a value's variance from a range. For example, if the range is $1,000.00 to $2,500.00, and the value is $3,000.00, I need it to return a variance of $500.00. If the value was $1,500.00, I need it to return a variance of $0.00 since it falls in the range. There may be occasions in which the range is $0.00 to $0.00, in which case any value would be a variance.

I have a built an adobe form with the following form fields:

1.) Low End of Range (Set to $ Format)

2.) High End of Range (Set to $ Format)

3.) Actual (Set to $ Format)

4.) Average (Set to $ Format, automatically generates the average based on the entry to "Actual" field)

5.) $ Variance (Set to $ Format, automatically calculates the $ variance of the average to the ranges defined in 1 and 2 above)

6.) % Variance (Set to % Format, to automatically valculate the % variance of the average to the ranges defined in 1 and 2 above)

**The problem I am having is when the user enters the high range they recieve an error saying "The valued entered does not match the format of the field [% Variance]". It does not seem to be causing an error with the calculation; however, I would like to find a way to avoid the error from displaying. **

I have the following custom JavaScript calculation in the % Variance field:

```
var Average = this.getField("Avg").value
var Low = this.getField("Low").value
var High = this.getField("High").value
var Variance = this.getField("Variance$").value
if (High== 0)
event.value = "";
else if(Average <= Low)
event.value = Variance / Low;
else if (Average >= High)
event.value = Variance / High;
```

I am pretty new to JavaScript, so I thank you in advance for your assistance!

Most Valuable Participant

Use this:

```
var Average = Number(this.getField("Avg").valueAsString);
var Low = Number(this.getField("Low").valueAsString);
var High = Number(this.getField("High").valueAsString);
var Variance = Number(this.getField("Variance$").valueAsString);
if (Average <= Low && Low!=0)
event.value = Variance / Low;
else if (Average >= High && High!=0)
event.value = Variance / High;
else event.value = "";
```

TOPICS

Acrobat SDK and JavaScript,
How to,
PDF forms

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Community Beginner
,

Apr 18, 2020

Copy link to clipboard

Copied

Hi,

I have an adobe form in which I need to calculate a value's variance from a range. For example, if the range is $1,000.00 to $2,500.00, and the value is $3,000.00, I need it to return a variance of $500.00. If the value was $1,500.00, I need it to return a variance of $0.00 since it falls in the range. There may be occasions in which the range is $0.00 to $0.00, in which case any value would be a variance.

I have a built an adobe form with the following form fields:

1.) Low End of Range (Set to $ Format)

2.) High End of Range (Set to $ Format)

3.) Actual (Set to $ Format)

4.) Average (Set to $ Format, automatically generates the average based on the entry to "Actual" field)

5.) $ Variance (Set to $ Format, automatically calculates the $ variance of the average to the ranges defined in 1 and 2 above)

6.) % Variance (Set to % Format, to automatically valculate the % variance of the average to the ranges defined in 1 and 2 above)

**The problem I am having is when the user enters the high range they recieve an error saying "The valued entered does not match the format of the field [% Variance]". It does not seem to be causing an error with the calculation; however, I would like to find a way to avoid the error from displaying. **

I have the following custom JavaScript calculation in the % Variance field:

```
var Average = this.getField("Avg").value
var Low = this.getField("Low").value
var High = this.getField("High").value
var Variance = this.getField("Variance$").value
if (High== 0)
event.value = "";
else if(Average <= Low)
event.value = Variance / Low;
else if (Average >= High)
event.value = Variance / High;
```

I am pretty new to JavaScript, so I thank you in advance for your assistance!

Most Valuable Participant

Use this:

```
var Average = Number(this.getField("Avg").valueAsString);
var Low = Number(this.getField("Low").valueAsString);
var High = Number(this.getField("High").valueAsString);
var Variance = Number(this.getField("Variance$").valueAsString);
if (Average <= Low && Low!=0)
event.value = Variance / Low;
else if (Average >= High && High!=0)
event.value = Variance / High;
else event.value = "";
```

TOPICS

Acrobat SDK and JavaScript,
How to,
PDF forms

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

bgb6

Apr 18, 2020
1
/t5/acrobat-sdk/javascript-calculation-value-does-not-enter-the-format-of-a-field/td-p/11060743
6
Replies
6

Most Valuable Participant
,

Apr 19, 2020

Copy link to clipboard

Copied

Community Guidelines

Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Reply

Loading...

try67

Apr 19, 2020
0
/t5/acrobat-sdk/javascript-calculation-value-does-not-enter-the-format-of-a-field/m-p/11062225#M6318
Community Beginner
,

Apr 19, 2020

Copy link to clipboard

Copied

Hello,

Thanks for the reply. I am very inexperienced when it comes to JavaScript, so how would I go about that?

I thought that is what I was doing with the

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

part of my formula?

Thank you in advance for your assistance!

Community Guidelines

Reply

Loading...

bgb6

Apr 19, 2020
0
/t5/acrobat-sdk/javascript-calculation-value-does-not-enter-the-format-of-a-field/m-p/11062458#M6320
Most Valuable Participant
,

Apr 19, 2020

Copy link to clipboard

Copied

What about the Low value?

Community Guidelines

Reply

Loading...

try67

Apr 19, 2020
0
/t5/acrobat-sdk/javascript-calculation-value-does-not-enter-the-format-of-a-field/m-p/11062482#M6322
Community Beginner
,

Apr 19, 2020

Copy link to clipboard

Copied

When I tried using the same formula for the low value it wouldn't calculate anything.

In some instances, if I have a range of lets say $0.00 to $1,000.00, and the average is $1,500.00. I need a percentage variance for the $500.00.

Community Guidelines

Reply

Loading...

bgb6

Apr 19, 2020
0
/t5/acrobat-sdk/javascript-calculation-value-does-not-enter-the-format-of-a-field/m-p/11062490#M6324
Most Valuable Participant
,

Apr 20, 2020

Copy link to clipboard

Copied

Use this:

```
var Average = Number(this.getField("Avg").valueAsString);
var Low = Number(this.getField("Low").valueAsString);
var High = Number(this.getField("High").valueAsString);
var Variance = Number(this.getField("Variance$").valueAsString);
if (Average <= Low && Low!=0)
event.value = Variance / Low;
else if (Average >= High && High!=0)
event.value = Variance / High;
else event.value = "";
```

Community Guidelines

Reply

Loading...

try67

Apr 20, 2020
0
/t5/acrobat-sdk/javascript-calculation-value-does-not-enter-the-format-of-a-field/m-p/11063320#M6326
bgb6
LATEST

Community Beginner
,

Apr 20, 2020

Copy link to clipboard

Copied

I think that worked! Thank you!

Community Guidelines

Reply

Loading...

bgb6

Apr 20, 2020
0
/t5/acrobat-sdk/javascript-calculation-value-does-not-enter-the-format-of-a-field/m-p/11065750#M6328
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.