Highlighted

Need PDF script that will add and multiply text boxes together

New Here ,
Sep 26, 2020

Copy link to clipboard

Copied

I know very little about scripts so please bear with me. First I'll explain what I did and then explain how I need to modify what I did to do something slightly different.

I originally wanted a text box ("ACRO_St") to display the value of a second text box ("Dex_B") automatically, but when a checkbox called "ACRO" was checked, ACRO_St would then display the value of Dex_B plus the value of a third text box called "Prof_B" (and I wanted a plus sign in front of the final value). Knowing zero about scripting but reading the help provided by forum users to others, I was able to accomplish what I wanted with the following script:

 

if (getField("ACRO").value=="Yes")
event.value = getField("Dex_B").value+getField("Prof_B").value;
else event.value = getField("Dex_B").value
if (event.value>0){var cr ="+"}else{var cr=""}AFNumber_Format(0,0,0,0,cr,true)

 

Now I want to modify this script so that, while continuing to do what it already does, if I then check a second checkbox called ("ACRO_Ex"), the text in "ACRO_St" would add the value of Dex_B with twice the value of Prof_B (i.e, Dex_B + (Prof_B x 2)). Any help in doing this from the geniuses in this community would be amazing.

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

106

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

Need PDF script that will add and multiply text boxes together

New Here ,
Sep 26, 2020

Copy link to clipboard

Copied

I know very little about scripts so please bear with me. First I'll explain what I did and then explain how I need to modify what I did to do something slightly different.

I originally wanted a text box ("ACRO_St") to display the value of a second text box ("Dex_B") automatically, but when a checkbox called "ACRO" was checked, ACRO_St would then display the value of Dex_B plus the value of a third text box called "Prof_B" (and I wanted a plus sign in front of the final value). Knowing zero about scripting but reading the help provided by forum users to others, I was able to accomplish what I wanted with the following script:

 

if (getField("ACRO").value=="Yes")
event.value = getField("Dex_B").value+getField("Prof_B").value;
else event.value = getField("Dex_B").value
if (event.value>0){var cr ="+"}else{var cr=""}AFNumber_Format(0,0,0,0,cr,true)

 

Now I want to modify this script so that, while continuing to do what it already does, if I then check a second checkbox called ("ACRO_Ex"), the text in "ACRO_St" would add the value of Dex_B with twice the value of Prof_B (i.e, Dex_B + (Prof_B x 2)). Any help in doing this from the geniuses in this community would be amazing.

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

107

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
Sep 26, 2020 0
Contributor ,
Sep 26, 2020

Copy link to clipboard

Copied

The code you posted above doesn't work.

Will at some point both checkboxes  be checked at the same time?

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...
Sep 26, 2020 0
New Here ,
Sep 27, 2020

Copy link to clipboard

Copied

It definitely works. I've used it multiple times. 

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...
Sep 27, 2020 0
Asim123 LATEST
Contributor ,
Sep 28, 2020

Copy link to clipboard

Copied

Where do you use that code?

I asume you use it in ACRO_St field as custom calculation script?

I recreate all your fields and that code doesn't work.

Also I ask again will there be situation when both checkboxes are checked or there will always be only 1 checked?

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...
Sep 28, 2020 1