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

JavaScript for Required Radio Button

New Here ,
Sep 02, 2021 Sep 02, 2021

I have created a form in Acrobat Pro that contains an E-mail button so the form can be e-mailed, however there are some fields (radio buttons) that are required to be completed before the form can be e-mailed. I have made this requirement within the Radio Button Properties, under the General tab, checking the Required checkbox.

I have a group of 7 radio buttons named Housing. One of the radio button statements is What type of housing does the family have: there are two radio buttons choices that follow that statement named HousingType; the two choices are Permanent and Temporary.

Is it possible to do the following? If the radio button for What type of housing does the family have: is selected, I would like to have the two radio buttons named HousingType to be required…but with javascript – not by checking the Required checkbox in the properties for HousingType.

I tried this already but what happened was if another radio button for Housing was selected I could not e-mail the form because a choice was not made for the Required radio buttons for HousingType of Permanent or Temporary.

The HousingType radio buttons are only relevant/needed if the radio button for the Housing statement What type of housing does the family have: is selected.

Please let me know if this is possible, and if so what would the javascript be.

 

Thank you, Jamie

TOPICS
Create PDFs , JavaScript , PDF forms
1.5K
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 02, 2021 Sep 02, 2021

As 'Mouse UP' event of "What type of housing does the family have:" button use this:

if(event.target.value == "What type of housing does the family have:")
this.getField("HousingType").required = true;

TIP:

You should also add script to other buttons to make those fields not required if user change his mind and select another button instead.

If you decide to do that, use this script instead in all 7 "Housing" buttons as 'Mouse UP' event:

this.getField("HousingType").required = event.target.value == "What type of housing does the family have:" ? true : false;

View solution in original post

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 ,
Sep 02, 2021 Sep 02, 2021

As 'Mouse UP' event of "What type of housing does the family have:" button use this:

if(event.target.value == "What type of housing does the family have:")
this.getField("HousingType").required = true;

TIP:

You should also add script to other buttons to make those fields not required if user change his mind and select another button instead.

If you decide to do that, use this script instead in all 7 "Housing" buttons as 'Mouse UP' event:

this.getField("HousingType").required = event.target.value == "What type of housing does the family have:" ? true : 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 ,
Sep 03, 2021 Sep 03, 2021
LATEST

This will work, but only until you reset the form, and then the required fields will remain so, even when the radio-button is no longer selected. That's why I prefer to use a calculation script for such tasks. It also makes it easier since you can control it all from one place, and don't have to apply a script to multiple fields.

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