Can a field name be changed with an incremented value based on a condition?

Explorer ,
Oct 26, 2017

Copy link to clipboard

Copied

I want to replace "X" in

  var chk = this.getField("PX.myCheck.chkAmount")

using an incremented value based on a condition.

My objective is to add script to this example so that if(num2.value > "") then the field name "PX.myCheck.chkAmount" will become "P1.myCheck.chkAmount". 

Example:

var num2 = this.getField("num.chk.02");

var i = 0

if(num2.value > "")(i = i + 1; var chk = this.getField("P1.myCheck.chkAmount";chk.value = num2.value);

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Yes: this.getField("P"+i+".myCheck.chkAmount")

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

87

Likes

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

Can a field name be changed with an incremented value based on a condition?

Explorer ,
Oct 26, 2017

Copy link to clipboard

Copied

I want to replace "X" in

  var chk = this.getField("PX.myCheck.chkAmount")

using an incremented value based on a condition.

My objective is to add script to this example so that if(num2.value > "") then the field name "PX.myCheck.chkAmount" will become "P1.myCheck.chkAmount". 

Example:

var num2 = this.getField("num.chk.02");

var i = 0

if(num2.value > "")(i = i + 1; var chk = this.getField("P1.myCheck.chkAmount";chk.value = num2.value);

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Yes: this.getField("P"+i+".myCheck.chkAmount")

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

88

Likes

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
Oct 26, 2017 0
Most Valuable Participant ,
Oct 26, 2017

Copy link to clipboard

Copied

Yes: this.getField("P"+i+".myCheck.chkAmount")

Likes

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
Reply
Loading...
Oct 26, 2017 0
Explorer ,
Oct 27, 2017

Copy link to clipboard

Copied

Thank you. I did not know that you could do that within the field name parenthesis. I thought the open and close quotes would be discarded with the result being this.getField(P1myCheck.chkAmount) rather than this.getField(“P1myCheck.chkAmount”). This is the simplest of solutions.

David

Likes

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
Reply
Loading...
Oct 27, 2017 0
try67 LATEST
Most Valuable Participant ,
Oct 27, 2017

Copy link to clipboard

Copied

The field-name parameter is just a string. As such, it can be manipulated just like any other string in your code.

Likes

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
Reply
Loading...
Oct 27, 2017 0