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

What is wrong with this code?

Explorer ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

Hi there!

The ultimate goal of this script is to set various field values throughout a form depending on what branch is chosen from a radio button group on the first page. I'm testing out the functionality with just two attributes - location name and address.

In my tests, I selected "KBAN" as my location and ran this in the console. It did not set the field values of ("LOCATION_NAME") and ("LOCATION_ADDRESS"), but it did return "321 XYZ Road" in the console window.

Any ideas why it won't set the field values?

Thank you!

var Location = this.getField("LOCATION").valueAsString; //radio button group

var arrLocations = ["KPOR",

                    "KBAN",

                    "KCON",

                    "KBUR",

                    "KRUT"];

var locIndex = arrLocations.indexOf(Location);

var arrName = ["Portland",

               "Bangor",

               "Concord",

               "Burlington",

               "Rutland"];

var arrAddress = ["123 ABC Road",

                  "321 XYZ Road",

                  "345 Any Road",

                  "543 Some Road",

                  "567 Another Road"];

var name = this.getField("LOCATION_NAME").value;

var address = this.getField("LOCATION_ADDRESS").value;

var arrFldAttributes = [name,

                        address];

var arrAttributeVals = [arrName,

                        arrAddress];

for (i=0; i < arrFldAttributes.length; i++) {

     arrFldAttributes = arrAttributeVals[locIndex];

}

TOPICS
Acrobat SDK and JavaScript

Views

643

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 , Jan 24, 2019 Jan 24, 2019

There you have saved the old values of the fields.

And with

arrFldAttributes =

you change only the values in this array.

Votes

Translate

Translate
Community Expert ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

Where did you set the field values?

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
Explorer ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

The purpose of the loop at the end is to set the field values.

arrFldAttributes is an array of the fields whose values I want to set, and arrAttributeVals is an array of arrays containing the values the fields should be set to.

for (i=0; i < arrFldAttributes.length; i++) {

     arrFldAttributes = arrAttributeVals[locIndex];

}

I'm sure I'm missing something simple here - just can't figure out what it is!

Thank you!

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 ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

There must be something like:

this.getField("LOCATION_NAME").value = ... ;

this.getField("LOCATION_ADDRESS").value = ... ;

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
Explorer ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

I've defined those as the variables "name" and "address" in lines 23 and 24. Shouldn't the array defined on line 26 point to those values to set?

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 ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

There you have saved the old values of the fields.

And with

arrFldAttributes =

you change only the values in this array.

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
Explorer ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

Thank you - I totally understand now!

Made some adjustments to the end of the code and it's now working:

var arrFldAttributes = ["NAME",

                        "ADDRESS"];

var arrAttributeVals = [arrName,

                        arrAddress];

for (i=0; i < arrFldAttributes.length; i++) {

this.getField("LOCATION_" + arrFldAttributes).value = arrAttributeVals[locIndex];

}

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 ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

LATEST

Or you can use something like this:

var arrFldAttributes = ["LOCATION_NAME", "LOCATION_ADDRESS"];

var arrAttributeVals = [arrName,

                        arrAddress];

for (i=0; i < arrFldAttributes.length; i++) {

    this.getField(arrFldAttributes).value = arrAttributeVals[locIndex];

}

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
LEGEND ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

getField sets up a connection with a form field. You get a field variable. If you get the "value" of a field variable you read from the form field (you do that). If you set the "value" of a form field you write to the form field (you don't do that).

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