These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to ensure only one of two text fields has a value?

MisterSnrub
Registered: Sep 27 2010
Posts: 16

Suppose I have two text fields Text1 and Text2. I want to make it so that when the user is done entering a value in Text1, then Text2's value should be set to "NA." Conversely, after a value is entered into Text2, then Text1's value should be changed to "NA." In other words Text1 and Text2 cannot both have distinct values. How do I do this?

My Product Information:
Acrobat Pro 10.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
You can set up both fields with custom calculation scripts like the following:

// Custom calculate script for Text1
var f = getField("Text2");
if (event.source && event.source === f) {
if (f.valueAsString) {
event.value = "NA";
} else {
event.value = "";
}
}


The script for Text2 would be the same, but replace "Text2" with "Text1". The code blanks the other field if the current field is blanked. You may not want this, but it seems reasonable to me.
MisterSnrub
Registered: Sep 27 2010
Posts: 16
Thanks for your response. I tried that and it works, but I wonder if it's intuitive enough for the end user.

How about this: Can we make so that if text is entered into one textfield, we empty out the other's value and also completely gray it out (like it's disabled)? That way if the user is using the Tab key, the second textbox is never entered, it just moves on to the next area? The textfield would then be re-enabled only if the original textfield is emptied.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
You could do that, but do you really think that would be more intuitive? I think an average user would have no idea how to activate the disabled field.

Also, what do you want grayed-out? If the field does not have any text, what do you want to be gray?

Finally, you say that you want to empty out the other field's value when text is entered into the other, but you also want to have the field disabled if the other field has text entered into it. You can't have it both ways, so you need to clarify how you want it to work.