Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Hi @,
Hope you are doing well. Thanks for writing in!
You can try the below steps and let us know if it works:
- Open your PDF form in Acrobat.
- Go to Prepare Form mode.
- Name the fields as follows for reference:
- "Yes_Checkbox"
- "No_Checkbox"
- "Explain_Field"
- Right-click on the No_Checkbox, select Properties > Actions tab.
- Under Select Trigger, choose Mouse Up.
- Under Select Action, choose Run a JavaScript, then click Add.
- Enter the following
- if (this.getField("No_Checkbox").value === "Yes") {
this.getField("Explain_Field").required = true;
} else {
this.getField("Explain_Field").required = false;
}
- if (this.getField("No_Checkbox").value === "Yes") {
Next, lock "Explain" Field When 'Yes' is Selected
- Right-click the Yes_Checkbox, select Properties > Actions tab.
- Under Select Trigger, choose Mouse Up.
- Under Select Action, choose Run a JavaScript, then click Add.
- Enter this
- 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;
}
- if (this.getField("Yes_Checkbox").value === "Yes") {
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
No, don't use them in the field names, only in your code.
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
Any chance you are available for a Zoom? lol I can't get it to work... 😞
Copy link to clipboard
Copied
If you'll provide more details we could help you out, but just saying "it doesn't work" is not very useful to us...
Copy link to clipboard
Copied
That's fair, my apologies!
I followed the above directions, but nothing happened. The field doesn't become required when no is selected, and the field doesn't become locked down when yes is selected.
Thank you again!
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for error messages. If you still can't figure it out, share the file with us, please.
Copy link to clipboard
Copied
Hello - Thank you for the feedback! I didn't get any error messages. This is the form in question.
Much, much appreciated! 🙂 April
Copy link to clipboard
Copied
I don't see any code anywhere in this file...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
THANK YOU, Try67!!! This worked and I genuinely appreciate the help and time on this! 🙂

