Skip to main content
Participating Frequently
October 13, 2020
Question

Need help making a second field appear/reappear when a box is checked or not.

  • October 13, 2020
  • 2 replies
  • 653 views

Hello! I'm hoping some one can help me out there.  I'm using Acrobat DC.  I have a form that has a small area that I can't seem to figure out how to make it do what I want, if it's even possible.  I would like a set of radio buttons to only appear if another check box is selected AND for them to dissapear when the check box is deselected.  I can make the first part happen by adding a "show/hide" action but this only works one time.  If the check box is deselected the radio buttons stay visible.  If this has to been accomplished by using a javascript, please site an example as I am a complete newbie at that.  Thanks!

This topic has been closed for replies.

2 replies

Karl Heinz  Kremer
Community Expert
October 13, 2020

Use the following as the checkbox mouse-up script - you will need to change the radio button name:

 

var rb = this.getField("RadioButtons");
if (event.target.value == "Yes") {
    rb.display = display.visible;
}
else {
    rb.display = display.hidden;
}

 

Participating Frequently
October 13, 2020

Karl, see my reply above to ls_rbls.  i also tried your script and had the same result.  thanks!

Karl Heinz  Kremer
Community Expert
October 13, 2020

I can assure you, it does work 🙂 I would start with a brand new document, and then just add a checkbox and a radio button group and then add this script to the checkbox mouse-up script. If that works, you know that there is something in your form that interferes with this script. If it does not work, then we can work on getting this to work in a simple form. Are you seeing any errors on the JavaScript console (Ctrl-J or Cmd-J on Mac)? 

ls_rbls
Community Expert
October 13, 2020

You need to employ a javascript action from the checkbox.

 

Open the checkbox properties --->>> go to the Actions tab--->>> "Mouse-up" action javascript,  and You copy the script below :

 

if (event.target.value =="Off") {
this.getField("myRadioButton").display = display.visible;
} else {
if (event.target.value =="Yes") {this.getField("myRadioButton").display = display.hidden;
}
}

 

 

ls_rbls
Community Expert
October 13, 2020

I made a mistake above .

 

This is the correct script:

 

if (event.target.value =="Off") {
this.getField("myRadioButton").display = display.hidden;
} else {
if (event.target.value =="Yes") {this.getField("myRadioButton").display = display.visible;
}
}
Participating Frequently
October 13, 2020

ls_rbls - thanks for help.  i'm getting closer! this script works but it only works once.  once the box has been checked and the hidden radio buttons appear, they do not disappear if the box is unchecked. is there a way to fix that?  thanks again