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

Select/deselect checkbox if text is entered/deleted from multiple text fields

Community Beginner ,
Dec 14, 2020 Dec 14, 2020

Copy link to clipboard

Copied

I'm creating a form in Acrobat DC. I have a checkbox named AN_PA_CB; its export value is "Proximate Analysis" (this cannot be changed because of other code in my form). I have three text fields named AN_PA_CP_TB, AN_PA_CF_TB, and AN_PA_A_TB. I need checkbox AN_PA_CB to check if text is entered in one or more of the three text fields AN_PA_CP_TB, AN_PA_CF_TB, and AN_PA_A_TB. I also need the checkbox to uncheck if text is deleted from all three text fields; however, the checkbox must stay checked if text remains in one or more of the fields.

 

I tried entering the code below in the custom format of each textbox:

this.getField("AN_PA_CB").checkThisBox(0,!/^\s*$/.test(event.value));

This checks/unchecks the checkbox successfully when text is added/deleted from a text field; however, this code considers each text field individually and unchecks the checkbox whenever text is deleted from any text field, even if the other two still contain text.

 

Is there a way for checkbox AN_PA_CB to check/uncheck dynamically when text is entered/delected from the three text fields? So all three text fields blank = checkbox unchecked, one or more text fields contains text = checkbox checked.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

210

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 14, 2020 Dec 14, 2020

Copy link to clipboard

Copied

Use a hidden text field. At calculation of this field check the content of your three text 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 ,
Dec 14, 2020 Dec 14, 2020

Copy link to clipboard

Copied

Thank you for the suggestion! I have used hidden calculation fields in the past, so I'm familiar with that. I just need help with writing the code that would accomplish what I'm trying to do - I'm a complete Javascript novice. 

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 14, 2020 Dec 14, 2020

Copy link to clipboard

Copied

LATEST

Use this as "Custom calculation script" in hidden field or in one of your text fields:

var f1 = this.getField("AN_PA_CP_TB").valueAsString;
var f2 = this.getField("AN_PA_CF_TB").valueAsString;
var f3 = this.getField("AN_PA_A_TB").valueAsString;
if(f1 != "" || f2 != "" || f3 != "")
this.getField("AN_PA_CB").value = "Proximate Analysis";
else this.getField("AN_PA_CB").value = "Off";

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