Javascript Variable undefined. Please help.

Participant ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Hello!
I'm working on a section in my code that finds a number in a field (Total+(parseInt(idx)+2) and depending on that number change the value of another field (Total+(parseInt(idx)+3)

Code here:

  function SetTotalValues(cID, idx) {
      this.getField("Total"+(parseInt(idx)+1)).value = 0.2 * this.getField("Total"+(parseInt(idx))).value;
      this.getField("Total"+(parseInt(idx)+2)).value = this.getField("Total"+(parseInt(idx))).value + this.getField("Total"+(parseInt(idx)+1)).value;

var getValue = [
      [3300, 194.25],
      [4000, 197.5],
      [238000, 1286.3],
      [Infinity, 999999],
];
var warranty;
var i;
      for (i = 0; i < getValue.length; i++) { 
      if ((this.getField("Total"+(parseInt(idx)+2)).value) > (getValue[i][0]) && (this.getField("Total"+(parseInt(idx)+2)).value) <= (getValue[i+1][0])){
       warranty = (getValue[i][1]); 
      }
      }
      this.getField("Total"+(parseInt(idx)+3)).value = warranty;
  }

The problem is that the warranty is undefined, I spent ages troubleshooting. Can someone help?

Thanks in advance.

Cheers.

 

TOPICS
Create PDFs, Edit and convert PDFs, General troubleshooting, How to, JavaScript, PDF forms

Views

5.2K

Likes

translate

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

Adobe Community Professional , Mar 26, 2021 Mar 26, 2021
Set a value, e.g.:var warranty = 0;

Likes

translate

Translate

Translate
Adobe Community Professional ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Set a value, e.g.:
var warranty = 0;

Likes

translate

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
Participant ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

@Bernd Alheit 
Changing the variable to 0 changes it to zero,

it should be running through this condition and it's not working.

var i;
      for (i = 0; i < getValue.length; i++) { 
      if ((this.getField("Total"+(parseInt(idx)+2)).value) > (getValue[i][0]) && (this.getField("Total"+(parseInt(idx)+2)).value) <= (getValue[i+1][0])){
       warranty = (getValue[i][1]); 

 any ideas?

Thanks for the help.

Likes

translate

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
Participant ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Nevermind !! 

Thank you

 

Likes

translate

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