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

Need Javascript for checkbox in PDF based on input from field

New Here ,
Oct 15, 2021 Oct 15, 2021

Would like to set 1 of 4 check boxes as "On" based on the value entered into a field with text field custom calculation , i.e.,

 

Enter 1 in field for  "Check Box1" = "On"

                                "Check Box2" = "Off"

                                "Check Box3" = "Off"

                                "Check Box4" = "Off"

 

Enter 2 in field for  "Check Box1" = "Off"

                                "Check Box2" = "On"

                                 "Check Box3" = "Off"

                                 "Check Box4" = "Off"

 

and so on...

 

Appreciate any help with this, thank you!

TOPICS
Acrobat SDK and JavaScript , Windows
2.2K
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

correct answers 1 Correct answer

Community Expert , Oct 15, 2021 Oct 15, 2021

You should give all the check-boxes the same name (say, "Check Box1"), and unique export values (1-4), and then use the following code as the custom calculation script in the text field:

 

if (event.value) this.getField("Check Box1").value = event.value;

else this.getField("Check Box1").value = "Off";

 

However, this will fail if the user enters some unforeseen value into the text field, such as "5" or "X"...

Translate
Community Expert ,
Oct 15, 2021 Oct 15, 2021

You should give all the check-boxes the same name (say, "Check Box1"), and unique export values (1-4), and then use the following code as the custom calculation script in the text field:

 

if (event.value) this.getField("Check Box1").value = event.value;

else this.getField("Check Box1").value = "Off";

 

However, this will fail if the user enters some unforeseen value into the text field, such as "5" or "X"...

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
New Here ,
Oct 16, 2021 Oct 16, 2021

Bingo! Thank you

 

The script does fail in the sense that none of the check boxes have a check, that is OK with me. The user of the form can always easily restart, however a warning or error message would be nice to add if an undesired value was input into the field. Still learning, but I have what I need for now. 

 

Script for future references:

 

var cAsk = "Enter One of: 1-Reviewed, 2-Rejected, 3-Revise, or 4-Furnish: ";
var cTitle = "Stamp status";


if(event.source.forReal &&
(event.source.stampName == "#axeWj0ZPWvEDlCFsbdmjaD"))
{
var nCheck = app.response(cAsk, cTitle);
event.value = nCheck;
}


if (event.value)
{
this.getField("CHECKBOX").value = event.value;}
else
{
this.getField("CHECKBOX").value = "off";}

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
New Here ,
Oct 16, 2021 Oct 16, 2021
LATEST

NOTE:

 

StampName "#axeWj0ZPWvEDlCFsbdmjaD" is specific for each individual stamp, name must be changed for anyone else trying to use the code.

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