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

Explorer ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

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

 

 

TOPICS
How to, JavaScript, PDF forms

Views

182

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

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 ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

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 ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Ok , thanks anyway - I guess I was expecting help with the script as I have rec'd from others in this community previously.  I understand some of the basic scripts, but this one was beyond my current level, and obviously you agree that it is more involved.  I'll try some google searches or youtube videos.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

LATEST

I had some time this morning, so take a look at this as the custom keystroke script for the SSN/EIN field. To enter a coustom keystroke script, you need to select a custom formatting script and then fill out the second part of the dialog. 

 

 

if (this.getField("Type").value != "SSN" && this.getField("Type").value != "EIN") {
	event.rc = false;
	app.alert("You need to select a type first");
} else {
	if (!event.willCommit) {
		var c = event.change;
		if (c == "" || (c >= '0' && c <= '9') || c == '-') {
			event.rc = true;
		} else {
			event.rc = false;
		}
	} else {
		var justDigits = event.value.replace(/\-/g, "");
		console.println(justDigits);
		console.println(justDigits.length);
		if (justDigits.length != 0 && justDigits.length != 9) {
			event.rc = false;
			app.alert("The SSN/EIN needs to have nine digits");
		} else if (justDigits) {
			// get the state of the "type" selection
			if (this.getField("Type").value == "SSN") {
				event.value = justDigits.substring(0, 3) + "-" + justDigits.substring(3, 5) + "-" + justDigits.substring(5, 9);
				event.rc = true;
			}
			else {
				event.value = justDigits.substring(0, 2) + "-" + justDigits.substring(2, 9);
				event.rc = true;
			}
		}
	}
}

 

Likes

Translate

Translate

Report

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