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

Display and hide subforms

PetafromOz
Registered: Jun 8 2009
Posts: 230
Answered

I haven't used LiveCycle for a while, so maybe I've lost my touch, cos I'm sure this ought to be the simplest thing in the world, but I can't make it work.

I've got checkboxes that say:

- Secondary
- Tertiary

Beside those I've got additional fields that include, what level they reached, what institution, what year, what country. I've wrapped those four fields into subforms - ie. SecondarySF, TertiarySF.

I only want those extra fields displayed if the user clicks a given checkbox - ie. if they click the Tertiary box, the fields within TertiarySF will be displayed.
That works fine. However I also want the relevant fields to disappear if the user goes back and 'unchecks' any box.

I've got a global var called sKill.
And this is what I have in a MouseUP event for my secondary & tertiary checkboxes.

if (sKill == "On");
{
TertiarySF.presence = "visible";
xfa.host.setFocus("TertiarySF.Qual");
}
elseif
{
(sKill == "Off");
EdPg.TertiarySF.presence = "hidden";
xfa.host.setFocus("EdPg.Adult");
}

Can someone please explain to me why this works when checked, but won't then hide those same subforms if subsequently unchecked?

Thanks,
Peta

from way... underground at Parkes - central West NSW - Australia

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The "if" and "else if" statements are not written correctly. The "On" portion will always be run and it should have errored out when it hit the "elseif". Did you see any errors in the Console Window?
try this:
if (sKill == "On");{TertiarySF.presence = "visible";xfa.host.setFocus("TertiarySF.Qual");}else{TertiarySF.presence = "hidden";xfa.host.setFocus("EdPg.Adult");}

Since this is for a check box the only possible values are checked or not checked. There's no need for a qualifier on the else portion. However, if you did need one you would write it like this:
if (sKill == "On"){TertiarySF.presence = "visible";xfa.host.setFocus("TertiarySF.Qual");}else if(sKill == "Off"){TertiarySF.presence = "hidden";xfa.host.setFocus("EdPg.Adult");}

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

PetafromOz
Registered: Jun 8 2009
Posts: 230
Hi thomp,

I tried that and LiveCycle didn't like it. It threw up an error at the 'else' statement. It was only happy if I made it 'elseif'.

Nonetheless I tried both of the above scenarios that you've provided and they don't work. In fact, doing it that way they don't even display the fields, let alone hide them again when unchecked.

I was wondering whether the problem lies in the fact that the fields are contained in a subform. I've been fooling around with the order of hiding the fields and subform and the only thing that works in terms of displaying them is to leave the fields as 'visible', but the subform as 'hidden'. But that doesn't fix my 'uncheck' problem.

Next I'm going to try removing the subform all together to see whether that will make any difference.

Thanks, Peta

from way... underground at Parkes - central West NSW - Australia

PetafromOz
Registered: Jun 8 2009
Posts: 230
OK, now something screwy's going on.

I gave up on Javascript, cos of course you're right, it should have been 'else', but it wouldn't let me go with that. So I converted it to Formcalc. I also removed the 'sKill var' because I mucked about with it so much.

So now this is what my Formcalc code looks like:

if (this.rawValue == "On") then

TertiarySF.presence = "visible"
xfa.host.setFocus("TertiarySF.Qual")

else

TertiarySF.presence = "hidden"
xfa.host.setFocus("EdPg.Adult")

endif

But here's the weird part - it works, in reverse! When I check the box, the subform is hidden, unchecked it displays. I have no idea why. Even though it made no sense, I even tried changing the first condition to "off" instead of "on" to see what happened and it changed nothing. It still hides the fields in checked mode and displays them when unchecked.

I double-checked that I had the values set up the right way around and the default, which is 'off'. That all looks fine.

But then I decided to change the value from "On" to 1 and did this:

if (this.rawValue == 1) then

TertiarySF.presence = "visible"
xfa.host.setFocus("TertiarySF.Qual")

else

TertiarySF.presence = "hidden"
xfa.host.setFocus("EdPg.Adult")

endif

And that works perfectly.
Why, I have no idea. And why LiveCycle wouldn't let me use the correct JavaScript syntax also bewilders me.

So I'm totally bamboozled now!!!
But I've got it working, although there has to be a logical reason why the JavaScript solution wouldn't work.

So I'd still love to know why if anyone has any ideas.

from way... underground at Parkes - central West NSW - Australia

PetafromOz
Registered: Jun 8 2009
Posts: 230
No wonder I drink!!!!!!!

OK, I give up.

Now I've done this using JavaScript:

if (this.rawValue == 1)
{
TertiarySF.presence = "visible";
xfa.host.setFocus("TertiarySF.Qual");
}
else
{
TertiarySF.presence = "hidden";
xfa.host.setFocus("EdPg.Adult");
}

And it works perfectly.
It's now accepting the 'else', and for the life of me I can't see what I did differently. Apart from changing the condition from "off" to 1. Except when I tried that before it didn't work. Now it does. I'm going mad!

But - it works.
So thanks heaps thomp, although somewhere something changed and I can't see what.

from way... underground at Parkes - central West NSW - Australia

PetafromOz
Registered: Jun 8 2009
Posts: 230
You know, the only thing I can see that's different, is that there is no colon at the end of the first line. I didn't think it mattered either way for the first line. Apparently I'm wrong.

Any thoughts?

from way... underground at Parkes - central West NSW - Australia

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Wow, that's quite a journey! But it's also how you really learn the material;) I was going to suggest that check boxes by default return 1 and 0 as values, but I didn't know what your "sKill" variable was and you can also change the export values it you want them to be "On" and "Off". I also wanted to clear up the syntax issue first.

The ";" is a terminator. You can't use it at the end of an "if" statment because then it will terminate the "if" block. I messed up on the first bit of code I provided because I left the ";" in. Sorry:( That's probably why the interpreter was complaining. It was seeing an "else" without an "if" attached to it. "for" and "while" loops are the same. Don't ever put a ";" at the end of the first line of the statement. Actually, the way the interpreter reads it is that the ";" is an empty line. So it thinks you have this situation:
if(this.rawValue == 1);// This line terminates the "if" statements{// Any thing inside the brackets is on it's own// Not attached to the "if"}

Hope this helps,
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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

PetafromOz
Registered: Jun 8 2009
Posts: 230
haha... absolutely it helps.
...and at this late stage I notice I said 'colon' when I meant semi-colon. Well... back to the red wine then...


In fact I've just been revisiting your e-seminar on LiveCycle that covers so many of the important basics to help me with adding lines on the fly. I think it's probably one of the most useful e-seminars I go back to.

Thanks again Thom.

from way... underground at Parkes - central West NSW - Australia