Skip to main content
Participating Frequently
March 17, 2025
Answered

Making a field required

  • March 17, 2025
  • 1 reply
  • 1695 views

Hi all,

I am working on a form with yes and no check boxes. This is one of the questions:

 

Did you verify the account activiny is in line with the investment profile?

No (If no, please explain.): ____________________

Yes

 

Is there a way if "No" is selected, the field to please explain is required for them to move on? If they choose 'No', then they MUST explain?

 

Conversely, is there a if 'Yes' is selected, the field to explain is locked down and they cannot enter any information? This one is not as important, but our reps need hand holding any chance they can get. So, we were thinking to lock down the explain field when 'Yes' is selected.

 

TIA!

 

Correct answer try67

PS. I had a closer look at the instructions above and they are not correct. You need to place both codes under both check-boxes for it to work properly. And of course you need to adjust the field names and values in them.

And actually, a better option is to do it through the Calculation event of the text field itself... I will adjust the code and send a new version soon.


Use this code:

 

if (this.getField("IPYN").valueAsString=="1") {
	event.target.required = true;
	event.target.readonly = false;
} else {
	event.target.required = false;
	event.target.readonly = true;
	event.value = "";
}

 

I also applied it already for you in the attached file.

1 reply

S_S
Community Manager
Community Manager
March 17, 2025

Hi @,

 

Hope you are doing well. Thanks for writing in!

 

You can try the below steps and let us know if it works:

  1. Open your PDF form in Acrobat.
  2. Go to Prepare Form mode.
  3. Name the fields as follows for reference:
    • "Yes_Checkbox"
    • "No_Checkbox"
    • "Explain_Field"
  4. Right-click on the No_Checkbox, select Properties > Actions tab.
  5. Under Select Trigger, choose Mouse Up.
  6. Under Select Action, choose Run a JavaScript, then click Add.
  7. Enter the following
    1. if (this.getField("No_Checkbox").value === "Yes") {
          this.getField("Explain_Field").required = true;
      } else {
          this.getField("Explain_Field").required = false;
      }

Next, lock "Explain" Field When 'Yes' is Selected

  1. Right-click the Yes_Checkbox, select Properties > Actions tab.
  2. Under Select Trigger, choose Mouse Up.
  3. Under Select Action, choose Run a JavaScript, then click Add.
  4. Enter this
    1. if (this.getField("Yes_Checkbox").value === "Yes") {
          this.getField("Explain_Field").readonly = true;
          this.getField("Explain_Field").value = ""; // Clears text if already entered
      } else {
          this.getField("Explain_Field").readonly = false;
      }

Note: This is a sample code that might or might not work for you. I am no expert with Scripting, and this is something I tried at my end.

 

Hope this helps.


Regards,
Souvik.

ALT46795Author
Participating Frequently
March 17, 2025

Thank you, Souvik! I will try now... quick question - when I rename the checkboxes, do I use the quotation marks?

 

"Yes_Checkbox" or Yes_Checkbox

 

Kind regards,

April

try67
Community Expert
Community Expert
March 17, 2025

No, don't use them in the field names, only in your code.