Skip to main content
Participating Frequently
October 4, 2018
Answered

Showing/Hiding multiple fields based on a checkbox is checked.

  • October 4, 2018
  • 2 replies
  • 4451 views

So, I have a form I am editing that someone else created.  Using adobe Acrobat Pro DC. In this form I've got checkboxes.  The first checkbox has javascript that I want to affect multiple fields - by showing or hiding them based on if the box is checked or not.  For background, the box is called "Brkfst", is the first box in the form and if checked, two other fields should appear - 1st is basically a label for the second box.  The first box is set to hidden by default and marked read only.  Default is set to the label title I want to show.  The second box is a text box for user input and is set to hidden.

The code I am trying to make work is in the actions under the Brkfst check box, and is set on the mouse up action, to run the following script:

var fieldHide = event.target.isBoxChecked(0)?display.visible:display.hidden;

this.getField("Expected Brkfst").display = fieldHide;

this.getField("BDeliver").dispay = fieldHide;

This code wasn't in the form when I got it, I put it there.  This works for the first box as expected, but I can't get the second box "BDeliver" to show or hide based on the check.  Am I missing something?  Originally neither would work, so I tried to "start over" by renaming the fields (the names are very long) to something shorter.  This worked to activate the first box "Expected Brkfst" but not the other.  I am far from a JavaScript person, just a girl learning how to do this stuff on the fly so any help would be great!

This topic has been closed for replies.
Correct answer try67

Don't know if this is helpful, but this is all the javascript I've put into this form (and they all work except for the checkbox showing "BkDeliver":

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<AcroForm>
//<ACRO_source>Brkfst:Annot1:MouseUp:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Brkfst:Annot1:MouseUp:Action1 ***********/
var fieldHide = event.target.isBoxChecked(0)?display.visible:display.hidden;

this.getField("BkDeliver").dispay = fieldHide;
this.getField("Expected Brkfst").display = fieldHide;
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>ContactEmail:Validate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:ContactEmail:Validate ***********/
var ContactEmail = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/; if (event.value!=""){if (!ContactEmail.test(event.value)){event.rc = false;app.alert("\"" + event.value + "\" is not a valid email address.");};};

//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Meeting_Date:Validate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Meeting_Date:Validate ***********/

if (event.value) { 
    var msPerDay = 86400000; 
    var today = new Date(); 
    var d = util.scand("m/dd/yy", event.value); 
    if ((d.getTime()-today.getTime())<(2*msPerDay)) { 
    app.alert("If your event is less than two business days from today, please contact amodenessi@ufcw.org.",1); 
   }    

//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>SUBMIT VIA EMAIL:Annot1:MouseUp:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:SUBMIT VIA EMAIL:Annot1:MouseUp:Action1 ***********/
   cToAddr = "MeetingRequest@ufcw.org"; "support@ufcw.org"; "security@ufcw.org"; "lhaynes@ufcw.org";

   cCCAddr = this.getField("ContactEmail").value;

   var cSubLine = "Meeting Request - "
                + this.getField("Meeting Room Reserved").value + ", Date: "                + this.getField("Meeting_Date").value;

    cBody = "Please include any approvals or additional details of your request for meeting space.\n" +
               "Thank you.";

   this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

//</ACRO_script>
//</AcroForm>


You wrote "dispay" instead of "display"...

2 replies

Participating Frequently
October 4, 2018

No, in the editor that comes up there is no debugging option.  Where would I run the debugger?  Thanks for the response!

Participating Frequently
October 4, 2018

OK, I found it.  Its says its not enabled, I will look into how to enable it and run it again.  There's some errors in there from my previous attempts I believe because its referencing an old field name.

try67
Community Expert
Community Expert
October 4, 2018

You can enable it under Edit - Preferences - JavaScript.

try67
Community Expert
Community Expert
October 4, 2018

The first step in debugging code problems is to check the JS Console for error messages. Did you do that?