Skip to main content
Inspiring
February 26, 2017
Question

Input field visibility based on a condition from another input field.

  • February 26, 2017
  • 1 reply
  • 3196 views

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!

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
February 27, 2017

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 = "";

}

rsbisaAuthor
Inspiring
February 28, 2017

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!

  1. var f1 = this.getField("Field1");
  2. var f2 = this.getField("Field2");  
  3. if (f1(event.value)>0) { 
  4.     f2.display = display.visible; 
  5.     f2.setFocus(); 
  6. } else
  7.     f2.display = display.hidden; 
  8.     f2.value = ""
  9. }
rsbisaAuthor
Inspiring
February 28, 2017

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.