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

How to copy information fields info when checkbox is marked 'Yes' in fillable PDF forms?

New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

I am trying to find a solution to make fillable PDF forms friendlier for my customers, and would like to have a solution that if they check a box as true, the following fields information would be feed by same information of above fields, so that they would avoid typing the same information more than once.

Is there a possibility to create such JavaScript or function?

TOPICS
Acrobat SDK and JavaScript

Views

360

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
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Yes, that's possible. However, do you want the users to be able to overwrite this information when the check-box is ticked, or should they always have the same values as the "original" fields in this scenario?

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
community guidelines
New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Thank you for a prompt reply!

I want that information appears in the fields after the checkbox is ticked (first option of your question), if it is not ticked, the fields have to remain without any data.

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
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Please read my question more carefully. You did not answer it.

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
community guidelines
New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Yes, apologies. As original value.

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
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Again, not what I asked. Let's try again: Do you want the users to be able to edit the fields where the values are copied to when the check-box is ticked? In other words, should it "lock" them which the check-box is ticked, or should it just copy the values at the moment you tick it, and that's it?

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
community guidelines
New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

It should copy the values at the moment checkbox is ticked.

Well, the logic should be like - if (checkbox is true then value.field2 = value.field1 else empty) 

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
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

As the MouseUp event of the check-box add the following code:

 

this.getField("field2").value = (event.target.value=="Off") ? "" : this.getField("field1").valueAsString;

 

Adjust the field names as needed.

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
community guidelines
New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Great! It worked!

Could you please additionally advice how the same condition should be applied when there are more than one field that should contain an original value? Should the same condition be written to all the fields separately adjusting only the names of the fields?

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
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Yeah, you can just duplicate that line, adjusting the field name in each case.

If you have a lot of fields for which you want to do this I can suggest a more efficient alternative, though.

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
community guidelines
New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

There are 7 fields for the same rule. Perhaps alternative way would be better.

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
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Use this:

 

var fields = ["field2", "field3", "field4"]; // enter actual field names here
for (var i in fields) {
	var f = this.getField(fields[i]);
	f.value = (event.target.value=="Off") ? "" : this.getField("field1").valueAsString;
}

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
community guidelines
New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Thank you very much for your support! The first script with several repetitions works perfectly. However, the alternative script hasn't worked properly as it gives me the same value to 7 fields; and I have tried to do several modifications to the values in brackets.

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
community guidelines
Community Expert ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Sorry, my mistake. Here's the correct code:

 

var sourceFields = ["field1", "field2", "field3"]; // the field names from which to copy the values
var targetFields = ["field4", "field5", "field6"]; // the field names to which to paste the values
for (var i=0; i<sourceFields.length; i++) {
	var targetField = this.getField(targetFields[i]);
	var sourceField = this.getField(sourceFields[i]);
	targetField.value = (event.target.value=="Off") ? "" : sourceField.valueAsString;
}

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
community guidelines
New Here ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

Now it works!

Thank you for your time and support!

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
community guidelines
Community Beginner ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hi, I'm trying to use the same code, but I get a syntax error at line 2 message. What can I do to fix it?

 

var sourceFields = [“RBCP.0”, “RegStartTime.1.0”, “RegEndTime.1.0”, “RegInstructionalMinutes.1.0”];

var targetFields = [“StCP1”, “StPrRegStartTime1”, “StPrRegEndTime1”, “StPrRegInstructionalMinutes.1”];

for (var i=0; i<sourceFields.length; i++) {

              var targetField = this.getField(targetFields[i]);

              var sourceField = this.getField(sourceFields[i]);

              targetField.value = (event.target.value=="Off") ? "" : sourceField.valueAsString;

}

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
community guidelines
Community Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

You must only use straight quotes (like this: " ), not curly ones (like this: “ ” ).

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
community guidelines
Community Beginner ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Thank you!

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
community guidelines
LEGEND ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

LATEST

This problem with quotes mostly happen if Word (or similar) is used to compose or collect scripts. Best just not to do that. Use Notepad if you're in Windows, to keep the text unchanged.

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
community guidelines