• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

3.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 04, 2018 Oct 04, 2018

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

Votes

Translate

Translate
Community Expert ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

You can enable it under Edit - Preferences - JavaScript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

OK, so I cleared the old errors out, deleted the script in the button, re-entered it and changed the name of the field I'm trying to hide so I could troubleshoot.  I purposely did not change the code "name" so I should expect an error...and I did

This is what I got:

TypeError: this.getField(...) is null

3:Field:Mouse Up

I'm assuming because the field name didn't exist.  But then I went into the javascript and corrected the field name and it still doesn't work.

Same error everytime I click the box:

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

TypeError: this.getField(...) is null

3:Field:Mouse Up

I've even deleted the box I'm trying to hide/show, put in a new box, new name and re-entered the script to reference the new field.  Still a no-go.  I'm lost?  What else can I do?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

LATEST

OMG, what an idiot.  Thank you! I guess I've just been staring at it too long.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines