Skip to main content
Participating Frequently
August 22, 2016
Answered

Show/hide fields based on user selection

  • August 22, 2016
  • 1 reply
  • 1281 views

I know some Javascript, but my first attempts to embed it in Acrobat are troublesome. I am creating a simple form where the user indicates via a checkbox how many people he or she needs to register, then the form shows that many fields to complete. I have been trying to get it to work with just one field before I add more.

In this sample I am just trying to get the second registrant field hidden if the user checks only 1 person to register. (I already know I'll have questions when it comes to needing to hide more than one field.)

if(event.target.value =="0") {

this.getField("Registrant2").display = display.hide;

}

This topic has been closed for replies.
Correct answer George_Johnson

That is correct--I have tied this code to the Mouse Up function in a check box. What I am trying to achieve is that when the box is checked (indicating only one attendee to an event), the second registrant field ("Registrant Two") is hidden.


Since I don't know what the export value is, try this:

if (event.target.value !== "Off") {

    this.getField("Registrant2").display = display.hidden;

}

You might want to add an else clause so that the field is shown when the check box is not selected:

if (event.target.value !== "Off") {

    this.getField("Registrant2").display = display.hidden;

} else {

    this.getField("Registrant2").display = display.visible;

}

If this does't work, you may not have the field name correct. Check the JavaScript console (Ctrl+J) to see of any errors are reported.

1 reply

Inspiring
August 22, 2016

As you'll see in the Acrobat JavaScript reference, the possible values for the display field property are:

display.visible

display.hidden

display.noPrint

display.noView

More info: Acrobat DC SDK Documentation

bnoofAuthor
Participating Frequently
August 22, 2016

Thanks. I am currently on page 86 of 769 in the "JavaScript for Acrobat API Reference," but hadn't found that yet.

However, updating the code to read like this still doesn't work:

if(event.target.value =="0") {

this.getField("Registrant2").display = display.hidden;

}

Inspiring
August 22, 2016

Did you place that code as the check box's Mouse Up script, or did you place it somewhere else? What is the export value of the check box?