Skip to main content
robertd66522140
Participating Frequently
October 12, 2020
Question

Validation script for a text field to be required based on dropdown selection not working!

  • October 12, 2020
  • 2 replies
  • 1767 views

Hi, I am working in Acrobat DC and created a terms and conditions form used for clients to sign and return.  One of the dropdown selections allow the client to either "Authorize" or "Not Authorized" us to use their credit card.  There are several text fields, whereby the default is "Not Required", however if they select "Authorize", I want those text fields to change to "Required".  I have tried custom validation scripts recommended in other posts, but when selecting the "Authorize" option in the dropdown, those text fields still DO NOT change to required.  The current script I am using is in the dropdown field:

 

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

 

I have also tried similar script in each of the text fields, but to no avail.

 

I also tried to use this.calculateNow(); in the document level javascript, but again, doesn't change text fields to required after the dropdown selection.

 

Summary, any of the custom validation scripts I have used don't change text fields from Not Required to Required when completing the form.

 

Can anyone help?

 

Thank you,

 

Bob

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
October 12, 2020

You can use this code as custom calculation script of dropdown field:

this.getField("Name of text field1").required = event.target.value == "Authorize" ? true : false;
this.getField("Name of text field2").required = event.target.value == "Authorize" ? true : false;

Add more field if you need.

robertd66522140
Participating Frequently
October 12, 2020

Hi Nesa, thank you so much for replying!  I just tried above and same result...when selecting "Authorize" from the dropdown, Text4 field still does not change to required.  Ugh!

Nesa Nurani
Community Expert
Community Expert
October 12, 2020

Did you change field name to Text4?

If you just want to change one field in this case "Text4" field use this code as custom calculation script of your dropdown field:

this.getField("Text4").required = event.target.value == "Authorize" ? true : false;

Also check that Authorize is spelled correctly and in drop down options tick 'commit selected value immediately'.

Bernd Alheit
Community Expert
Community Expert
October 12, 2020

Why does you compare event.value with "OTHER" ?

robertd66522140
Participating Frequently
October 12, 2020

Sorry, my laziness, that was the sample code.  Actual code for the dropdown is (trying to get text field "Text4" to be required)

 

this.getField("Text4").required = (event.value=="Authorize");