Expand my Community achievements bar.

Changing presence of text field on different subform with JavaScript

Avatar

Level 1

I am developing an audit form for my company.  One of the requirements is to have check boxes that either show or hide text fields depending upon the check box's state.  I currently have one form (form1) that has two subforms (Worksheet21 & Worksheet 22).  On Worksheet21 there is a check box named None21.  The initial state of None21 is unchecked.  One Worksheet22 there is a text field with the name None22.  The initial presence of None22 is invisible as set through the object palette.  I need to have a script that causes None22 to become visible when None21 is checked and invisible when None21 is unchecked.  Right now I'm stuck on just getting None22 to become visible.  Here is the code thus far that I have been trying:

form1.Worksheet21.None21::click - (JavaScript, client)

var c=Worksheet22.None22.presence                                                  //Retrieve None22's initial presence for error checking purposes

xfa.host.messageBox("Node: "+c,"Start",2,2);                                      //Message box displays "Node: invisible" and None22 is not showing on the form

var i=this.rawValue;                                                                           //Using this for debugging and error checking

xfa.host.messageBox("Value: "+i,"Test",2,2);                                      //When None21 is checked the message box displays "Value: 1"

     if(this.rawValue==1){                                                                    //Check if None21 is checked

          xfa.host.messageBox("Should show now","Showing",2,2);         //Have this in place just so I know the next line should make None22 visible

          Worksheet22.None22.presence="visible";                                //Set None22's presence to visible

          c=Worksheet22.None22.presence;                                         //Retrieve None22's presence to check if the presence was changed

          xfa.host.messageBox("Node: "+c,"Done",2,2);                        //Message box displays "Node: visible" however None22 is not showing on the form

     }

As the comments show, apparently the presence of None22 is being changed from invisible to visible but it is not being see on the page.  I am using LiveCycle Designer ES V8.2.1.3144.471865 and viewing the form in Acrobat 9 Pro V9.0.0.  I am also saving the file as an Adobe Dynamic XML Form.  I am an experience programming (VB.NET) and haven't programmed in JavaScript in almost 10 years and just started with LiveCycle about a week ago and this is driving me crazy.  Any help would be greatly appreciated. 

5 Replies

Avatar

Level 1

Okay...I figured out how to make it work by changing None22's presence to hidden in the object palette.  Maybe someone can explain why it worked with hidden and not with invisible.  What is the difference between these two?

Avatar

Level 1

Further issue:

I tried adding additional subform (Worksheet32, Worksheet33, and Worksheet34) and each has a hidden text field called None32, None33, and None34 respectively.  I used the same code that worked, however sometimes it only make None32 visible and other times it makes all three text fields visible, without ever changing the code.  I changed the target version in the options to Acrobat 9.0 and Acrobat 8.0 and it didn't help.  This is the latest incarnation of the code:

form1.#subform[5].None31::click - (JavaScript, client)

if(this.rawValue==1){

     Worksheet32.None32.presence="visible";

     Worksheet33.None33.presence="visible";

     Worksheet34.None34.presence="visible";

}

else{

     Worksheet32.None32.presence="hidden";

     Worksheet33.None33.presence="hidden";

     Worksheet34.None34.presence="hidden";

}

Why does it only execute the first instruction in the if statement, and sometimes execute all three?

Avatar

Level 1

Okay last bit of information I can provide.  I opened up the JavaScript Debugger in Acrobat 9 Pro to see if there were any errors.  The following is show in the window.

Acrobat JavaScript Debugger Functions Version 9.0

Acrobat EScript Built-in Functions Version 9.0

Acrobat Annotations / Collaboration Built-in Functions Version 9.0

Acrobat Annotations / Collaboration Built-in Wizard Functions Version 9.0

Acrobat SOAP 9.0

Worksheet34.None33 has no properties

4:XFA:form1[0]:#subform[5]:None31[0]:clickException in line 4 of function top_level, script XFA:form1[0]:#subform[5]:None31[0]:click

Worksheet34.None33 has no properties

4:XFA:form1[0]:#subform[5]:None31[0]:click

Now, looking back at the code in LiveCycle the script is:

form1.#subform[5].None31::click - (JavaScript, client)

if(this.rawValue==1){

Worksheet32.None32.presence="visible";

Worksheet33.None33.presence="visible";

Worksheet34.None34.presence="visible";

}

else{

Worksheet32.None32.presence="hidden";

Worksheet33.None33.presence="hidden";

Worksheet34.None34.presence="hidden";

}

The bold line is Line 4 according to the script editor in LiveCycle.  It is Worksheet34.None34 not Worksheet.None33.  At one point it was (I was copying and pasting to save time and then just changing the numbers.)  It almost appears that when I save the form in LiveCycle, that the JavaScript is not being update in the saved file for some reason?  I've been working on this form for three hours and can't figure this out.  Any direction in fixing this would be so greatly appreciated.

Avatar

Level 1

Hopefully this will be my last update to my current problem.  I discovered that I can make the error repeatable (sometimes working vs. sometimes not working.)  If I check None31 then the text fields None32, None33, and None34 all work correctly.  However if I select None21 even once, then None32 will hide/unhide when None31 is selected, but None33 and None34 will not, and None41/None51 will not work.  So what I have so far, all the check boxes will work until check box None21 is used (selected for the first time) and then all will stop working (except None31 will partial work).  If I never select None21 then all the check boxes will work as planned.  I'm at a lost on how to proceed with this now.

Avatar

Level 8

You may want to post the question in the Designer or Forms forum.  There are a lot of form specific JavaScript experts

who watch those forums exclusively.