These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Display selected Subforms depending on Drop Down Menu

AlScott
Registered: Nov 2 2007
Posts: 123
Answered

OK - I've looked everywhere I can on this one, and have now admitted defeat over what will prove to be a simple answer.

I've created a form.
I have a 'drop-down-list' box with various actions eg:

New Install
Broken Seal
EPROM replacement.

Now depending on the selected menu item an appropriate number of subforms will be displayed for the User to complete. To take the first option for an example:

A New Install will require Subforms 1,4,5,6,7,8 (ie not subforms 2 & 3)

And so on....

The fields are dynamic.

Thanks
Al

My Product Information:
LiveCycle Designer, Windows
goodbye
Registered: Jul 7 2008
Posts: 49
you use the event.change I believe to do this:

TopmostSubform.Page1.myDropDown::change - (JavaScript, client)
if (myDropDown.xfa.event.change == "MyValue") {
someSubForm.presence = "visible";
someOtherSubForm.presence = "visible";
}
else {
someSubForm.presence = "invisible";// or "hidden"
someOtherSubForm.presence = "invisible";// or "hidden"
}
AlScott
Registered: Nov 2 2007
Posts: 123
Great thanks!!
I'll give this a try tonight (afterall I'm here until 3:00am PST). Let you know how I get on.
Feedback much appreciated!!!
Al
AlScott
Registered: Nov 2 2007
Posts: 123
Hey - Subquark,
Any objections to dropping you a copy of the file so we could have a brain-storm on this one.
I can see exactly what you mean, and yes it does sound logical, no joy at this end though.
Now the form which this section if relates to is all on page #2 of a 2 page form - as is the 'drop-down" menu - thus I'm wondering if it's necessary to put the ".Page#" into the syntax......

Here's what I've put into the Javascript box for the 'dropdown"

----- form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIIReportTitle.ServicePerformed::change: - (JavaScript, client)

if (form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIIReportTitle.ServicePerformed.xfa.event.change == "Broken Seal") {
form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIISection1.presence = "visible";
else {
form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIISection1.presence = "hidden"};
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Take a look at this eseminar video, it explains most of what you want to do.

https://admin.adobe.acrobat.com/_a200985228/p87746471/

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

goodbye
Registered: Jul 7 2008
Posts: 49
well alscott, I am far from a pro, been at this for three weeks now but I think my logic is flawed. well at least if you want someone to open, partially fill, then reopen and continue.

I watched your video Thom, it was great, but I am not tech enough to apply it to my specific example. I did learn several new things from it that I am using today (especially how to flow a form, you are a godsend on that).

alscott, my understanding is related to client run JS, is that what you are doing?

open your form and select the drop down and then in the Show window of the script pane select the "change" event. that is where your code should go for the drop down action (i don't know what that means about putting the code in the drop-down box?)

the path does need to point right at the box, you can use a tip Thom illustrates which is to place the cursor in the script pane and then find the drop-down and do CTRL left click for a relative path or CTRL left click for an absolute path to the dropdown

i'll be glad to look at your form and offer my fledgling advice: dmiller "at" newmarketinc "dot" com
AlScott
Registered: Nov 2 2007
Posts: 123
Yup - all working noe.
Subquark - your text worked!!
Excellent tutorial thom!!
Thanks
Al
AlScott
Registered: Nov 2 2007
Posts: 123
Well,
I've managed to get the correct subforms to display/hide when I choose the first item from a DROP DOWN menu.
(Thanks to Thomp and ssubquark!!)
But now I've run into a another problem.
As I described earlier there are several different options for this form:
New Installation
Broken Seal
EPROM Replace
...
The form itself is broken down into 9 subforms.
So - a New Installation might requires sections 1,4,5,6,7,8 to be visible, but 2 & 3 invisible (ie not necessary to complete.and a Broken Seal needs only 1,3,5,6 & 8 - again the other subforms to be 'invisible'Here's the java:
if (form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIIReportTitle.ServicePerformed.xfa.event.change == "New Installation") then
ClassIISection1.presence = "invisible";
ClassIISection3.presence = "invisible";
ClassIISection2.presence = "visible";
ClassIISection4.presence = "visible";
ClassIISection5.presence = "visible";
ClassIISection6.presence = "visible";
ClassIISection7.presence = "visible";
ClassIISection8.presence = "visible";
ClassIISection9.presence = "visible";
}

That much works fine!

Now if the User selects: Broken Seal a different set of subforms will be displayed.

If I try to use an 'endif' or 'else' type command to append this next group nothing happens at all.

FormCalc reference from the 'helpfile' suggests:
"if ( simple expression ) then
list of expressions
elseif ( simple expression ) then
list of expressions
else
list of expressions
endif"

So - should I be using FormCalc or Java?? If so how? There are 5 options for the user to choose from resulting in various combinations of the 9 subforms.

Help! As brain is now fried!
thanks
Al
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You're syntax for the "if" statment is incorrect. In [b]JavaScript[/b] an if is written like this.
if(expression){statments

}else{statements

}

There is no "then" after the "if" condition. And the statements executed by the if are enclosed in cury brackets "{".

You could use FormCalc as well. For this type of thing there is very little difference in the languages. The only thing that's important is that the syntax is correct and consistent for whatever language you are using.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

AlScott
Registered: Nov 2 2007
Posts: 123
Hi Thomp,
Sorry about the duplicatiion.
Yup - that syntax worked great. Was so near to it too at 3:00am this morning before I went home.
:)
AlScott
Registered: Nov 2 2007
Posts: 123
Thomp,
Sorry to bother you again, but I cannot get the subforms to "flow" up the page as selections are chosen.

For each subform the Content is set as "Flowed" and the "Flow Direction" is "Top to bottom"

The file is saved as "Dynamic" and it's an interactive form.

Here's part of the code covering just a couple of the subforms that are dependent on the selection from the drop down menu.

Everything else works great - it's only the 'flow'.....

----- form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIIReportTitle.ServicePerformed::change: - (JavaScript, client)

if (form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIIReportTitle.ServicePerformed.xfa.event.change == "New Installation") {
ClassIISection1.presence = "hidden";
ClassIISection3.presence = "hidden";
ClassIISection2.presence = "visible";
ClassIISection4.presence = "visible";
ClassIISection5.presence = "visible";
ClassIISection6.presence = "visible";
ClassIISection7.presence = "visible";
ClassIISection8.presence = "visible";
ClassIISection9.presence = "visible";
}
else
if (form1.ClassIIIncidentReportForm.ClassIIReportFormTotal.ClassIIReportTitle.ServicePerformed.xfa.event.change == "Broken Seal") {
ClassIISection7.presence = "hidden";
ClassIISection2.presence = "hidden";
ClassIISection4.presence = "hidden";
ClassIISection1.presence = "visible";
ClassIISection3.presence = "visible";
ClassIISection5.presence = "visible";
ClassIISection6.presence = "visible";
ClassIISection8.presence = "visible";
ClassIISection9.presence = "visible";
}
else

I'm sure there's a more "graceful" way of doing this too. I have got a 'test-bed' I created using FormCalc and all is great there..........
Thanks
Al