Copy link to clipboard
Copied
I would like a text field to format based on which checkbox is selected:
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
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.
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.
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.
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.
Copy link to clipboard
Copied
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;
}
}
}
}