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

Radio Button Required Field

New Here ,
Jul 02, 2024 Jul 02, 2024

Hello Community

I have multiple questions on an adobe form that are radio button.

Three fields, Yes, No, If yes explain

How can I make this whole question a required field, but not require "If yes", when no is selected. Here is the example:

CHPHR_0-1719931398836.png

 

I have seen answers posted but they tend to be a tad confusing. I am not well versed in scripting. And which goes where. I am using Adobe Acrobat Cloud version I know how to add the script  just need to know if required or read only need to be checked for each and what script goes with which button

 

What script goes in "Group1"  yes?

 

What Script goes in "Group1" no?

 

What Script goes in "If yes"?

 

Thank you

TOPICS
JavaScript , PDF , PDF forms
578
Translate
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 ,
Jul 02, 2024 Jul 02, 2024

You only need a script for the "if yes" field. Let's assume that the export values for your "YesNoGroup" are set to "Yes" and "No" (you do that on the Options tab as "Radio Button Choice"), the following script for your text field should result in the desired behavior:

 

// get the value of the radio buttons
var yesNo = this.getField("YesNoGroup").value;

if (yesNo == "Yes") {
   event.target.required = true;
}
else {
   event.target.required = false;
}

 

Translate
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
New Here ,
Jul 02, 2024 Jul 02, 2024

wow much appreciated I will give it a whirl!

Translate
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
New Here ,
Jul 02, 2024 Jul 02, 2024

I did add this script to "Text1" but when i chose "yes" option, and deliberately didnt add text in "text 1" it did not flag it as required field when i hit submit button. I am sure it is me missing something.

Buttons are called "Group1"

Yes is called "Text1"

 

CHPHR_0-1719936953899.png

 

You mention export value. there is no option for export value as there are in check boxes

CHPHR_1-1719937585856.png

thanks for your patience with this newbie scripter!

 

Translate
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
New Here ,
Jul 02, 2024 Jul 02, 2024

PS the screen capture cut it off but it does say:

 

// get the value of the radio buttons
var yesNo = this.getField("Group1").value;

if (yesNo == "Yes") {
event.target.required = true;
}
else {
event.target.required = false;
}

 

Translate
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 ,
Jul 02, 2024 Jul 02, 2024

Do you get any error messages in the JavaScript console (Ctrl-J on Windows or Cmd-J on macOS)? Does the field in question get the red outline that indicates that it is a required field? 

Translate
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 ,
Jul 02, 2024 Jul 02, 2024
LATEST

I notice you have a lower case y in "yes" in your description.  It could be a typo, but these values are case sensitive.  If your export value is "yes" instead of "Yes", it won't work.

Translate
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