Copy link to clipboard
Copied
I'm creating an HR form in Acrobat Standard X (Windows, if that matters). For 401k deductions, the user can input either a percentage of their paycheck or a dollar amount (two different fields). Is there a way to configure this so users can enter data in only one of the fields, but not both? Here is a screen shot of what the form looks like:
Thanks,
-- Jonathan
Copy link to clipboard
Copied
You can set up a custom validation script for each field that resets the other field if the users enters a value. For example, suppose you have two fields named t1 and t2. The validation script for the t1 field could be:
// Custom validation script
if (event.value) getField("t2").value = "";
and for t2:
if (event.value) getField("t1").value = "";
You'd have to change the field names to match what you're using.
Copy link to clipboard
Copied
You can set up a custom validation script for each field that resets the other field if the users enters a value. For example, suppose you have two fields named t1 and t2. The validation script for the t1 field could be:
// Custom validation script
if (event.value) getField("t2").value = "";
and for t2:
if (event.value) getField("t1").value = "";
You'd have to change the field names to match what you're using.
Copy link to clipboard
Copied
Thank you! That works perfectly.
At the risk of being difficult, can I add one more wrinkle? Is it possible to use these validation formulas while still validating the numbers being entered? Specifically, making sure the percent (it's actually being entered as a number, since the percent sign is hard-coded on the form) is between 0 and 100, and the dollar entry field is between 0 and 750?
Copy link to clipboard
Copied
It's certainly possible. Here's a link to a sample form: Shared Files - Acrobat.com
It includes a document-level JavaScript that includes a function that's called in the validate event of both text fields. The min and max validation values are hardcoded, but you could make it more general by passing the values to the function. I didn't set the numeric formatting since I didn't know exactly what you wanted.
Copy link to clipboard
Copied
It looks like your sample file does exactly what I want it to, and hard-coded limits are fine.
Unfortunately, you're reaching the extent of my Acrobat expertise here. How does one add or edit document-level Javascripts in Acrobat 10 Standard? I looked all over, but couldn't find it under File, Tools, or other menu options. Is this a feature that's only available in Acrobat Professional?
Copy link to clipboard
Copied
You can't with Acrobat Standard, unfortunately, at least not easily. It's technically possible via a script or by importing a properly constructed FDF, but then editing is a problem. All of it is tedious and you wouldn't have this problem with Acrobat Pro.
An alternative is to place the code that you'd normally place in document-level JavaScripts in a Page Open script on the initial page. For single page PDFs this won't be a problem, but for multipage PDFs it can be since variables get reinitialized when the initial page is revisited.
Here's the script that's been rewritten so you can specify a minimum and maximum value when you call it:
// Page Open JavaScript
function resetOtherField(f_name, min, max) {
// Limit entries to the specified range
AFRange_Validate(true, min, true, max);
// If the entry was validated above...
if (event.rc) {
// Get a reference to the other field
var f = getField(f_name);
// If this field is not blank...
if (event.value) {
f.value = ""; // ...clear the other field
}
}
}
And you'd call it like this in the validate event of a text field (e.g., "t1"):
// Custom validation script
resetOtherField("t2", 0, 750);
I didn't give that function the best name, so you could change it to something more descriptive if you want.
Copy link to clipboard
Copied
Thank you again. You've been exceedingly helpful. Given my (and Acrobat Standard's) limits, I'll note that for future reference.
-- Jonathan
Find more inspiration, events, and resources on the new Adobe Community
Explore Now