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

How to insert text if a certain check box is selected?

Community Beginner ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

I am creating a court order form, and there is an option for New Commitment, or to Release the defendant, both with fillable checkboxes. On the 2nd page is an order that I'd like to have the text change based on which one is selected. Is there a user friendly way to do this or would I have to rely on a script? I would need this to work on computers without Acrobat Pro as I'm the only one who has the Pro version. 

TOPICS
Create PDFs , Edit and convert PDFs , How to , PDF forms

Views

3.5K

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

You will need a script for that. It should work in Acrobat Reader for sure and probably on most other apps, but probably not on mobile.

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 Beginner ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

Do you know what i would need to add? Sorry my knowledge of Acrobat is basic at best since I do not use it most of the time. 

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

Something like this as 'Calculation' script of text field:

if(this.getField("Checkbox1").valueAsString != "Off")
event.value = "Text for checkbox 1 goes here";

else if(this.getField("Checkbox2").valueAsString != "Off")
event.value = "Text for checkbox 2 goes here";

else
event.value = "";

 

Change checkbox names in script (Orange text) to the names of your checkboxes.

Change blue text to the messages you want to show.

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 Beginner ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

Thank you! That worked. Last question I swear, do you know if I'd be able to hide the 2nd page(like it just doesn't exist) unless one of the two checkmarks is selected and how I would go about doing it? 

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 Beginner ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

But I might need an if then conditional to check for a 2nd box to be selected because sometimes a different order is needed

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

You can make a template out of a page and make it hidden by default, then if needed you can spawn it with a script.

Here is a basic script to spawn template if checkbox is checked, As Mouse UP action of checkbox:

var t1 = getTemplate("template name");
if (event.target.value != "Off"){
t1.spawn({nPage: numPages, bRename: false, bOverlay: false});}

 

You first need to make a template from a page by selecting 'Organize Pages' tool, then click on a page you wish to make into template, then on the toolbar click 'More' and 'Page Templates', then give your template a name and click 'add' and uncheck checkbox next to template name to make it hidden by default.

In script where it says "template name" change it to the name you gave to your template.

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 Beginner ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

What would I do to hide the 2nd page if... let me just get a picture here so its easier to follow

 

4aa8d2b858feb74243f008b4f3d47792.png

 

so say I check off Release, it spawns an order as per your instructions, but then I check off Detention Motion Denied, the 2nd page is still there but I want to delete it, is there a javascript to hide the 2nd page again, and to even hide it again if I uncheck all the checkboxes? I was searching around but couldn't find a java to remove the page that would work on reader. 

 

 

If I didn't explain well I will try to add an example 

 

I check off New Commitment by accident, the template page is spawned, I uncheck the box and select Continued Commitment(which doesn't need an order), but the 2nd page is still there. 

Example 2: I check off Release(which needs an order) and the sub-checkbox Detention Motion Denied(which  doesn't need an order), I would like the 2nd page to be removed. 

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

To delete a page, use this.deletePages() it uses 'start' and 'end' positions.

Example: this.deletePages({nStart: 0, nEnd: 2}); or this.deletePages(0,2);

nStart (optional) The 0-based index of the first page in the range of pages to be deleted. The
default is 0, the first page in the document.

nEnd (optional) The last page in the range of pages to be deleted. If nEnd is not specified,
only the page specified by nStart is deleted.

 

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 Beginner ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

So the order will always be the 2nd page, I have this: if (event.target.value != "Off"){
; this.deletePages(1));}, which returns a syntax error because I guess I'm missing a semicolon, would that code work or would it end up returning nothing? 

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 Beginner ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

Actually scratch that, I ended up getting it by using 

var t1 = getTemplate("template name");
if (event.target.value != "Off"){
this.deletePages(1);}, thank you so much! 

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 ,
Apr 14, 2023 Apr 14, 2023

Copy link to clipboard

Copied

You got an error because you had an extra semicolon.

You don't need part with red text, it's to get a template, it has nothing to do with deleting a page.

var t1 = getTemplate("template name");
if (event.target.value != "Off"){
this.deletePages(1);}

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 ,
Aug 28, 2023 Aug 28, 2023

Copy link to clipboard

Copied

LATEST

Hello!

 

Follow up to the above, how do I make it so when multiple check boxes are checked, the associated words from both populate in the same text field one after another?  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