Skip to main content
Participant
July 24, 2023
Question

Conditional Logic

  • July 24, 2023
  • 1 reply
  • 542 views

Hi all,

 

After several hours of searching I am stuck. I have a check box group: Separation Type with two options either Voluntary or Involuntary. After they check one of the boxes, a text field should be required with reasons.

 

Ex. if they select voluntary separation, a drop down will appear where the reason for separation is required, Currently I have a code where if the checkbox is selected, the field is required: this.getField("VoluntaryDropdown").required = event.target.value!="Off";

 

However, if someone checks the Voluntary and then decides they meant to check the Involuntary, both fields now become required when only one should be requried.

 

Any advice or guidance is appreciated!

 

-M

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
July 24, 2023

You need to put the same script in both checkboxes in the MouseUp event.

This script needs to use the export values of the checkboxes to determine which field is required. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
MM0216Author
Participant
July 24, 2023

Hi Thom,

 

Thank you so much for getting back to me so quickly!

 

Thank you for this advice as I added it to each checkbox and it worked where now the text is required if the respective checkbox is checked.

 

However I wanted to test this form thoroughly as it will be shared with an entire organization with a submit button included on the form. When testing the form I wanted to see what would happen if I checked the Voluntary Check Box and then decided to switch and check the Involuntary check box. It seems that when I do this, it is now requiring something for both the Voluntary & Involuntary text although only the Involuntary Check Box is checked.  It seems once the box is checked, even if unchecked, the field is required because when I did this and selected Submit I ran into an error that said "At least one required field was empty. Please fill in the required fields (highlighted) before continuing"

 

Is there a way to set it up where if the box is unchecked then it is no longer required? Or maybe adding a script where if someone checks one box, the other box is no longer required? Im not sure if this is possible but figured this would be my best shot at figuring it out.

 

Thanks,

M

Nesa Nurani
Community Expert
Community Expert
July 25, 2023

Set in each checkbox the other field to be not required, something like this:

Voluntary Checkbox:

this.getField("VoluntaryDropdown").required = event.target.value!="Off";
this.getField("InvoluntaryDropdown").required = false;

Involuntary Checkbox:

this.getField("InvoluntaryDropdown").required = event.target.value!="Off";
this.getField("VoluntaryDropdown").required = false;