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

Javascript for auto populate field based on checkboxes

Community Beginner ,
Mar 31, 2023 Mar 31, 2023

Copy link to clipboard

Copied

I guess the title of the discussion is a bit misleading because I have already figured out how to fill out a text field based on the value entered on another text field if a certain box is checked, however: 

If the second checkbox is checked (var b2), I would like the user to be able to free text in that field. So essentially, I am asking how do I write Javascript for "Free Text" in an if statement. 

 

I tried not having a second variable at all, however, if the user accidentally selects the first checkbox, the value remains in the text field even if the checkbox is unchecked afterwards. 

 

var b1 = this.getField("RCB1").isBoxChecked(0);
var b2 = this.getField("RCB1").isBoxChecked(1);

if(b1)
event.value = this.getField("DLAST").value

if(b2)
event.value = (????????????????)

TOPICS
Acrobat SDK and JavaScript , Windows

Views

815

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 ,
Mar 31, 2023 Mar 31, 2023

Copy link to clipboard

Copied

You can use only condition for b1 or use script in checkbox.

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 ,
Mar 31, 2023 Mar 31, 2023

Copy link to clipboard

Copied

What do you mean? 

I was able to condition for b1 and b2. For example, if I wanted b2 to autopopulate the fields based on other fields not stated in b1, I am successfully able to do so ... so I am unsure exactly how I can only condition for b1. Regardless, I am just trying to find how I can clear the fields via javascript and then allow the client to enter their own information. For now, I have conditioned the fields via Action tab to just reset the fields. 

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 ,
Mar 31, 2023 Mar 31, 2023

Copy link to clipboard

Copied

I purely think I am misunderstanding what you are saying. 

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 ,
Mar 31, 2023 Mar 31, 2023

Copy link to clipboard

Copied

LATEST

If you wish for client to manually enter info, you have a couple of options.

1. If you are using calculation script, and you wish b1 to autopopulate and b2 to be for manual input, then don't use b2 option in your script, use only b1 like this:

var b1 = this.getField("RCB1").isBoxChecked(0);

if(b1)
event.value = this.getField("DLAST").value;

If b2 is selected, then the script won't trigger, and you can input info.

 

2. Another option is to use scripts in checkbox instead.

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