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

Require that one of two form fields is filled

Community Beginner ,
Mar 15, 2019 Mar 15, 2019

I have two fields on a form, we'll say A and B, and need to require that either A or B is filled out (but not necessarily both). So essentially, like a radio button, but for text fields. Any suggestions?

TOPICS
PDF forms
5.0K
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 ,
Mar 15, 2019 Mar 15, 2019

OK. Here's how I would do it. Define both fields as required and then use the following custom validation script in each one:

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

event.target.required = true;

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 ,
Mar 15, 2019 Mar 15, 2019

"Require" in what sense, 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 ,
Mar 15, 2019 Mar 15, 2019

The same way that you can make a single field "required," I'd like to apply that to two fields but just require that one or the other is completed. It's actually for a W-4 that we're having new hires at our company complete, and we need to ensure that they either put in a withholding amount OR they complete the "Exempt" box.

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 ,
Mar 15, 2019 Mar 15, 2019

OK. Here's how I would do it. Define both fields as required and then use the following custom validation script in each one:

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

event.target.required = true;

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 ,
Mar 15, 2019 Mar 15, 2019

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 ,
Apr 11, 2023 Apr 11, 2023

Hello! Where do you type the validation in?

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 ,
Apr 12, 2024 Apr 12, 2024

Hi! I'm trying to use this formula but getting the error message "Invalid forumla expression. [Cursor Position 5]:
unknown function "."

 

Do you mind helping me figure out how to input the formula correctly?

Alexandra249730040agt_0-1712948230639.png

 

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 ,
Apr 12, 2024 Apr 12, 2024
LATEST

Hi! I'm trying to use this formula but getting the error message "Invalid forumla expression. [Cursor Position 5]:
unknown function "."

 

Do you mind helping me figure out how to input the formula correctly?

Alexandra249730040agt_0-1712948256984.png

 

 

 

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