Skip to main content
starryeyed223
Participant
December 14, 2020
Question

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

  • December 14, 2020
  • 2 replies
  • 418 views

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.

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
December 15, 2020

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";
Bernd Alheit
Community Expert
Community Expert
December 14, 2020

Use a hidden text field. At calculation of this field check the content of your three text fields. 

starryeyed223
Participant
December 14, 2020

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.