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

Require text field conditional on drop down menu selection

Community Beginner ,
Aug 28, 2018 Aug 28, 2018

I have a form with a drop down menu.  If a user selects "OTHER" from the dropdown menu, I want to make a text field required to be filled in before they can submit the form.  What is the javascript I would need to run in the dropdown menu action under properties?

TOPICS
PDF forms
4.4K
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 ,
Aug 29, 2018 Aug 29, 2018

Use this code as the custom validation script of the drop-down field:

this.getField("Name of text field").required = (event.value=="OTHER");

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 ,
Aug 29, 2018 Aug 29, 2018

Use this code as the custom validation script of the drop-down field:

this.getField("Name of text field").required = (event.value=="OTHER");

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 ,
Nov 12, 2018 Nov 12, 2018

Hi.  I am trying to do something similar, and keep getting an error on one part.  I have a dropdown for "Add" or "Change" with each having different fields that are required depending on what is selected.  Everything works OK when "Change" is selected.  I'm having the issue with "Add" - I'm guessing that's because more fields are required when choosing "Add".  Here is the script I currently have:

this.getField("Vendor ID for changes only").required=(this.getField("Add / Change").valueAsString=="Add");
this.getField("Address").required=(this.getField("Add / Change").valueAsString=="Change");
this.getField("City").required=(this.getField("Add / Change").valueAsString=="Change");
this.getField("State").required=(this.getField("Add / Change").valueAsString=="Change");
this.getField("ZIP").required=(this.getField("Add / Change").valueAsString=="Change");
this.getField("Phone").required=(this.getField("Add / Change").valueAsString=="Change");
this.getField("Contact").required=(this.getField("Add / Change").valueAsString=="Change");
this.getField("Dropdown13").required=(this.getField("Add / Change").valueAsString=="Change");
this.getField("Enter fax # or email address").required=(this.getField("Add / Change").valueAsString=="Change");

Any help you can offer is greatly appreciated!

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 ,
Nov 12, 2018 Nov 12, 2018

What is the issue, exactly?

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 Beginner ,
Aug 29, 2018 Aug 29, 2018

Thank you!

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 ,
Jun 21, 2020 Jun 21, 2020

Had same problem. This helped. Thank you.

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
Explorer ,
Jul 21, 2022 Jul 21, 2022
LATEST

What if another selection on the drop down menu is selected? How can we hide the text field again?

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