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

Javascript Variable undefined. Please help.

Participant ,
Mar 25, 2021 Mar 25, 2021

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
6.1K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 26, 2021 Mar 26, 2021

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

View solution in original post

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

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

Translate
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

@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.

Translate
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
LATEST

Nevermind !! 

Thank you

 

Translate
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