Skip to main content
Participant
Oct 16, 2021 5:19 AM UTC
Answered

Need Javascript for checkbox in PDF based on input from field

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!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Oct 16, 2021 6:53 AM UTC

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"...

3 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Oct 16, 2021 6:53 AM UTC

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
Participant
Oct 16, 2021 12:40 PM UTC

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
Participant
Oct 16, 2021 12:43 PM UTC

NOTE:

 

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

Translate