Skip to main content
Known Participant
March 23, 2021
Question

Format text field based on checkbox selected - Acrobat 2020 / Forms

  • March 23, 2021
  • 1 reply
  • 1568 views

I would like a text field to format based on which checkbox is selected:

  • Two checkboxes (TaxType)  values SSN or EIN
  • One text field (TaxID)
  • User will always enter 9 digits
  • SSN: NNN-NN-NNNN or EIN: NN-NNNNNNN
  • TaxID number may start with a zero (0) so I don't want that number ignored
  • If User attempts to type in number without first checking box, can I stop them and create an error message that tells them to choose box first?

Is there a validation script I can run to achieve this?  I would think this would be very common.

And yes, it would be easier if there were two separate text fields without the checkboxes, but the department requesting doesn't want it set up that way!

Thank you!

~Michelle

 

 

This topic has been closed for replies.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
March 23, 2021

You can prevent a user from entering data by e.g. making the field read-only unless a valid format is selected. If the field is read-only, you would not have to look for user input and process it. You could also e.g. fill in some explanatory text in the form field when no format is select 

 

You can accomplish the two differnet formats with a custom format script. The way I would do this is by removing anything that is not a number and then testing for 9 characters (and if there are not 9 digits, report an error), and then inserting the dashes where required, based on the selected format. 

Known Participant
March 23, 2021

Thank you Karl.  However, I don't know how to accomplish what you are suggesting.  I'm primarily concerned about the SSN vs TIN format. 

So, assuming I place the script in the text box, how do I say if SSN is checked then format NNN-NN-NNN else if EIN is checked format as NN-NNNNNNN else field is blank.

Karl Heinz  Kremer
Community Expert
Community Expert
March 23, 2021

This does require a JavaScript format script. With the standard tools you have avaiable in a form, you cannot do that, so you need to either create this script yourself (and potentially learn JavaScript programming along the way), or find somebody who can do this for you. If you want to start learning JavaScript for Acrobat, take  look here:  http://khkonsulting.com/2017/01/learning-to-program-javascript-for-adobe-acrobat/

 

If a probem can be solved with just a few lines of JavaScript, I usually post a short script, but this is unforatunately a bit more involved.