Skip to main content
Participant
January 4, 2017
Answered

PDF form with data in field A or B, but not both

  • January 4, 2017
  • 1 reply
  • 741 views

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

This topic has been closed for replies.
Correct answer George_Johnson

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.

1 reply

George_JohnsonCorrect answer
Inspiring
January 4, 2017

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.

Participant
January 4, 2017

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?

Inspiring
January 4, 2017

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.