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

How do I auto populate a text field from multiple checkboxes?

Community Beginner ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

I'm working on a pdf form with 10 check boxes. I’d like the user to be able to select one or more checkboxes and have the text associated with each checkbox auto populate an editable text field. I entered the script below for the first two checkboxes "VL1" and "VL2" as a test, but the event value for both checkboxes doesn’t display at the same time. Only one shows. If this is working correctly, the user can create a list from the checkboxes and enter text for the TIMELINE, PEOPLE RESPONSIBLE, etc. for each. I am not familiar with JavaScript and am piecing this together from other posts (most useful to me was this one https://answers.acrobatusers.com/What-code-I-auto-populate-text-field-checkbox-activated-q215636.asp...). Perhaps there is an easier way to do this. Any help is greatly appreciated!

 

var v1 = this.getField("VL1").value;

if(v1 != "Off"){
event.value = "Video record a live session on a phone or computer and post it on YouTube or your organization’s website. \n\n TIMELINE-\n PEOPLE RESPONSIBLE-\n RESOURCES AVAILABLE-\n MEASURES OF SUCCESS-\n --------------------------------\n";
}

var v2 = this.getField("VL2").value;

if(v2 != "Off"){
event.value = "Collect videos or podcasts that you and your program staff would recommend that parents/caregivers view. Put these in one easy-to-find location and share the links with parents/caregivers. \n\n TIMELINE-\n PEOPLE RESPONSIBLE-\n RESOURCES AVAILABLE-\n MEASURES OF SUCCESS-\n --------------------------------\n";
}

 

Views

3.3K

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

correct answers 1 Correct answer

Community Expert , Dec 31, 2019 Dec 31, 2019

Change this line:

event.value = "Collect videos..."

To:

event.value += "Collect videos..."

And add this to the top of your code:

event.value = "";

Votes

Translate

Translate
Community Expert ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

Is this an Acrobat question... if now, which Adobe program?

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 ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

Yes I am creating the form in Acrobat DC. 

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 ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

So, did you enter this script as a calculation on the field that is displaying the text?

 

If so, then the script presents a conflict. There are two different check boxes with two different messages. What happens when both are checked? Are the messages added together? does one have presedence over the other?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Dec 30, 2019 Dec 30, 2019

Copy link to clipboard

Copied

Yes I entered the script as a calculation on the text field. The problem is when both checkboxes are checked the message for VL2 erases the message for VL1 and I want both messages to show at the same time if the boxes are checked.

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 ,
Dec 31, 2019 Dec 31, 2019

Copy link to clipboard

Copied

Change this line:

event.value = "Collect videos..."

To:

event.value += "Collect videos..."

And add this to the top of your code:

event.value = "";

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 ,
Dec 31, 2019 Dec 31, 2019

Copy link to clipboard

Copied

That works perfectly! Thanks so much for your help and quick response. Much appreciated!

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 ,
Feb 13, 2020 Feb 13, 2020

Copy link to clipboard

Copied

I have a follow on question to this post. The code works to populate the feild when the check boxes are checked. I'd like to be able to edit the text in the feild after it populates. It doesn't seem like this is possible because when I type in the text then click out of the text feild, the new text I typed in disappears. Is there a way to allow the feild to be edited after it has been populated?

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 ,
Aug 08, 2020 Aug 08, 2020

Copy link to clipboard

Copied

Hey sharil this is late answer to your question.

 

Use this line at the beginning of  your custom calculation script:

 

if (event.source && event.source.name =="myField") {

 

//and add your code here

 

}

 

 

 

NOTE: Credit to Try67 who coached on me this.

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 ,
Aug 09, 2020 Aug 09, 2020

Copy link to clipboard

Copied

LATEST

It is generally a bad idea to make a field that is both automatically set, and editable. To do this you need to clearly define when the field is in either state.  Does the user entry override any future changes to the check boxes, or do changes to the checkbox automatically override the entered value? 

One solution is to add another checkbox that explicitly allows for data entry. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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