Input field visibility based on a condition from another input field.
Copy link to clipboard
Copied
I have a PDF form with several input fields. I want to have a particular field made visible, only when preceding field provides a specific response. Here's the layout:
Input Field1: A list box with three possible choices. The values of the three choices are 0, 1, and 2, respectively. If the selected value is > 0, I want another input text box, Field2, to newly appear adjacent to Field1
Input Field2: How many units of Field1 did you use?
Basically, I want User to simply move on to Field3, Field4, etc. if they are selecting the 0 response in Field1. I do not want them to type a number in Field2 unless the proper conditions are present from Field1. More importantly, I want their attention drawn to Field2 because of its abrupt appearance when answering Field1 with 1 or 2.
I do understand that if Field1 = 0, then any number typed in Field2 would be meaningless, mathematically. That's not the point. I want to draw attention to Field2 because that response is critical to the whole project if Field1 = 1 or 2.
Thanks!
Copy link to clipboard
Copied
You can use this code as the custom validation script of Field1:
var f2 = this.getField("Field2");
if (Number(event.value)>0) {
f2.display = display.visible;
f2.setFocus();
} else {
f2.display = display.hidden;
f2.value = "";
}
Copy link to clipboard
Copied
Thank you. But I'm struggling a bit. The code makes Field2 not visible. But I'm not clear where the value that makes it visible/not visible comes from. In my scenario, f2 would be checking to see if another field, f1, had a value greater than 0. In your script, is "Number" serving as f1? If so, don't I have to declare Number? What's wrong with the below.
Thanks!
- var f1 = this.getField("Field1");
- var f2 = this.getField("Field2");
- if (f1(event.value)>0) {
- f2.display = display.visible;
- f2.setFocus();
- } else {
- f2.display = display.hidden;
- f2.value = "";
- }
Copy link to clipboard
Copied
Well. Have you ever just posted a question, and just after posting it the answer just comes to you.
I figured it out. I had f1 and f2 flip-flopped in my actual script. The above example works.
Copy link to clipboard
Copied
By "example above" do you mean my code or yours? Because yours is not going to work...

