• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Calculations Not working in my Function

New Here ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

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

1.1K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , 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
...

Votes

Translate

Translate
Community Expert ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

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. 

Votes

Translate

Translate

Report

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

Copy link to clipboard

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

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;

Votes

Translate

Translate

Report

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

Copy link to clipboard

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

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;

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

It worked, Thank you for your help

Votes

Translate

Translate

Report

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