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

Function to retrieve and assign values to a number of form fields using a multi-dimensional array

Engaged ,
Feb 12, 2022 Feb 12, 2022

I believe I need another set of eyes to review the script (provided below) for a function (script) intended to assign values to a number of form fields that rely solely upon the use of a multi-dimensional array. For some odd reason, the form fields only display the initialized values assigned to the form fields by the variables created/associated inside the script. Other than that, I am not getting any error messages regarding syntax. For whatever reason, I just can't seem to identify the problem with the script provided below. Any comments, suggestions. regarding the script are most appreciated. Thank you ahead of time.

 

// function to calculate /assign form field values using a multi-dimensional array
function calculatePrices() {
var systemType = getField("systemType."+i);
var quantity = this.getField("quantity."+i);
var agreeType = getField("agreeType."+i);
var agreeYear = getField("agreeYear."+i);

//create and initialize variables for form fields
var year1 = 0;
var year2 = 0;
var year3 = 0;
var year4 = 0;
var year5 = 0;
var year6 = 0;
var inspectionCharge = 0;
var total = 0;

if(systemType.value > -1 && agreeType.value > -1 && agreeYear.value > -1) {
if(agreeType.value==0){
year1 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][0];
year2 = aSystemsPricing[systemType.value][agreeType.value][agreetYear.value][1];
year3 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][2];
year4 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][3];
year5 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][4];
year6 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][5];
total = quantity.value * (year1 + year2 + year3 + year4 + year5 + year6);
}
if(agreeType.value==1){
year1 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][0];
year2 = aSystemsPricing[systemType.value][agreeType.value][agreetYear.value][1];
year3 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][2];
year4 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][3];
year5 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][4];
total = quantity.value * (year1 + year2 + year3 + year4 + year5 + inspectionCharge);
}
if(agreeType.value==2){
year1 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][0];
year2 = aSystemsPricing[systemType.value][agreeType.value][agreetYear.value][1];
year3 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][2];
year4 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][3];
year5 = aSystemsPricing[systemType.value][agreeType.value][agreeYear.value][4];
total = quantity.value * (year1 + year2 + year3 + year4 + year5);
}
}

//assign pricing to calculated form fields
getField("year1."+i).value = year1;
getField("year2."+i).value = year2;
getField("year3."+i).value = year3;
getField("year4."+i).value = year4;
getField("year5."+i).value = year5;
getField("year6."+i).value = year6;
getField("inspect."+i).value = inspectionCharge;
getField("total."+i).value = total;
}

TOPICS
General troubleshooting , How to , JavaScript , PDF forms
5.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
Community Expert ,
Feb 15, 2022 Feb 15, 2022

I get following error:


ReferenceError: j is not defined
2:Document-Level:populateAgreeYear

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 ,
Feb 16, 2022 Feb 16, 2022

Instead of giving you fish after fish, I will try to teach you how to fish...

When you have an error message about something being undefined it means you're trying to access something that doesn't exist. In this case it's in your data object (aSystemPrices), so one of the values you're passing to it doesn't exist in it. So try to find out which one it is.

Add commands to your code to print out all three variables (systemType, agreeType and agreeYear), and see if their values are what you expect them to be. They try to print out the data-object values for them, and see if they are all valid:

aSystemPrices[systemType.value]

aSystemPrices[systemType.value][agreeType.value]

aSystemPrices[systemType.value][agreeType.value][agreeYear.value]

aSystemPrices[systemType.value][agreeType.value][agreeYear.value][0]

etc.

This will help you narrow down and locate the issue.

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
Engaged ,
Feb 16, 2022 Feb 16, 2022
LATEST

Able to finally resolve all my form issues while pulling an all nighter in which event my interctive PDF form performs as intended without a glitch. Thanks again to Bernd and Try67 for all your help not to mention that the Acrobat console played an important role even though it sometimes appears to be a PITA as I now recall when using a number of years ago. All said, my last question is, howw does one who periodically visits the forum to ask a question or questions like myself check only one correct answer when there may be answers or comment from several individuals that are or were all helpful? 

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