## Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.

• Calculations Not working in my Function

# Calculations Not working in my Function

New Here ,
Apr 27, 2021 Apr 27, 2021

Copied

I have written a code to make a calculation based on the option selected, but it´s not running the 2 lines above, only the last one

var Pacote = this.getField("Pacote").value;
if( Pacote > 4 ) event.value = 45;
else if( Pacote > 3 ) event.value = 35;
else if( Pacote > 2 ) event.value = 40;
else if( Pacote > 1 ) event.value = 30;
else if( Pacote > 0 ) event.value = 25;
else event.value = 0;

var Nuggets = this.getField("Nuggets").value;
if( Nuggets > 29 ) event.value = Nuggets * 0.5333333;
else if( Nuggets > 14 ) event.value = Nuggets * 0.75;
else if( Nuggets > 9 ) event.value = Nuggets * 0.80;
else if( Nuggets > 6 ) event.value = Nuggets * 0.857142857;
else if( Nuggets > 0 ) event.value = Nuggets;
else event.value = 0;

event.value = ( this.getField("Nuggets").value * this.getField("Pacote").value );

I tried add the {, but i don´t know if I am doing right

Any help is much appreciated

TOPICS
JavaScript, PDF forms

Views

681

Likes

Report

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

Adobe Community Professional , May 04, 2021 May 04, 2021
You just changed names, I meant something like this: var Pacote = Number(this.getField("Pacote").value); var p = 0; if( Pacote > 4 ) p = 45; else if( Pacote > 3 ) p = 35; else if( Pacote > 2 ) p = 40; else if( Pacote > 1 ) p = 30; else if( Pacote > 0 ) p = 25; var Nuggets = Number(this.getField("Nuggets").value); var n = 0; if( Nuggets > 29 ) n = Nuggets * 0.5333333; else if( Nuggets > 14 ) n = Nuggets * 0.75; else if( Nuggets > 9 ) n = Nuggets * 0.80; else if( Nuggets > 6 ) n = Nuggets * 0.857...

Likes

6 Replies 6
Apr 27, 2021 Apr 27, 2021

Copied

What want you calculate? What is wrong with :

event.value = ( this.getField("Nuggets").value * this.getField("Pacote").value );

The last line overrides the result of the previous calculations.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
May 01, 2021 May 01, 2021

Copied

Yes, i want to take the "nuggets" results, which is a conditional result from above and multiple for "pacote" result, wich is also a condinional result from above, but only the last line works, not the conditionals one, the same goes if I move the line: event.value = ( this.getField("Nuggets").value * this.getField("Pacote").value ); for the top, only the last line works

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 01, 2021 May 01, 2021

Copied

If I understand right, instead of event.value use variables, for example: use var p for pacote and var n for nuggets and then at the end call: event.value = p*n;

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
May 04, 2021 May 04, 2021

Copied

Not sure if i undestando correctly, but I change somethings

var P = this.getField("P").value;
if( P > 4 ) event.value = 45;
else if( P > 3 ) event.value = 35;
else if( P > 2 ) event.value = 40;
else if( P > 1 ) event.value = 30;
else if( P > 0 ) event.value = 25;

var N = this.getField("N").value;
if( N > 29 ) event.value = N * 0.5333333;
else if( N > 14 ) event.value = N * 0.75;
else if( N > 9 ) event.value = N * 0.80;
else if( N > 6 ) event.value = N * 0.857142857;
else if( N > 0 ) event.value = N;

event.value = P*N

But still, the only line that works is the last one

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 04, 2021 May 04, 2021

Copied

You just changed names, I meant something like this:

``````var Pacote = Number(this.getField("Pacote").value);
var p = 0;
if( Pacote > 4 ) p = 45;
else if( Pacote > 3 ) p = 35;
else if( Pacote > 2 ) p = 40;
else if( Pacote > 1 ) p = 30;
else if( Pacote > 0 ) p = 25;

var Nuggets = Number(this.getField("Nuggets").value);
var n = 0;
if( Nuggets > 29 ) n = Nuggets * 0.5333333;
else if( Nuggets > 14 ) n = Nuggets * 0.75;
else if( Nuggets > 9 ) n = Nuggets * 0.80;
else if( Nuggets > 6 ) n = Nuggets * 0.857142857;
else if( Nuggets > 0 ) n = Nuggets;

event.value = p*n;``````

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
May 05, 2021 May 05, 2021

Copied

LATEST

It worked, Thank you for your help

Likes

Report

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