Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Display hidden radio button on mouse click

Avatar

Level 2

Hello. I am hoping someone can point me in the right direction. I'm working on creating a form where a new section appears upon a particular mouse click of a particular radio button. I tried creating a two subforms where one has the clickable radio button and the other is the hidden section of the document. I've tried a script I found in the forum (see below) to get the subform to hide when it is selected as visible in the object palette, but I can't reverse it yet. It also only hides Text3 and does nothing with the other objects. Do I need to name them first for this to work? I believe I've seen simpler ways to do this in the forum in the past, but have not been successful in finding these posts again.

Thanks in advance.

form1.#subform[0].#subform[1].SubForm1.KSPP.001::click - (JavaScript, both)

if (this.rawValue==null)
{
    Text3.presence= "visible";
    Text2[3].presence= "visible";
    Text2[4].presence= "visible";
    Text2[5].presence= "visible";
    xfa.host.beep("1");
}
else
{
    Text3.presence= "hidden";
    Text2[3].presence= "hidden";
    Text2[4].presence= "hidden";
    Text2[5].presence= "hidden";
    xfa.host.beep("3");
}  

5 Replies

Avatar

Level 10

Hi,

You have multiple objects with the same name. This is your problem with the script, particularly as you are using JavaScript. FormCalc would be a little easier in this case.

However I would recommend that unless you have a very good reason for having the same names, then I would rename them and adjust the script.

Have a look at this post and the associated PDF sample for discussions on how to reference objects in scripts. http://assure.ly/kUP02y. If you don't want to read the post, you can go straight to the sample here: http://assure.ly/mxZO9T.

Hope that helps,

Niall

PS: even your pages are unnamed!

Avatar

Level 2

Hi Niall

Thank you for such a great resource! I've done a lot of reading and a lot of learning since. I understand why you send me documents that explain resolve nodes. However, after naming everything that's being referenced and going through a couple of tutorials, I'm still having the same problem. Below is my new script. When the document is opened in Acrobat Pro, the section (now a seperate subform) is visible and becomes hidden upon the button click. That's the opposite I want to happen. When I change the presence of supplement to hidden, the button click does not make it visible at all. Also, and maybe I'm misunderstanding how the script is read, but in the first scenario where the presence is marked as visible and supplement becomes hidden upon button click, it does not become visible again if the button value changes from 0. I've tried applying this script to both the singular radio button in a set of three, and to the set as a whole. Same results.

SCID.page1.Gate.KSCP_001.No_Information::click - (JavaScript, both)

if (this.rawValue=0)
{
    xfa.resolveNode("SCID.page1.supplement").presence="visible";
}
else
{
    xfa.resolveNode("SCID.page1.supplement").presence="hidden";
}

Avatar

Level 10

Okay,

If your objects are uniquely named, then you should not need to use xfa.resolveNode at all.

Looking at your script:

  • The root node is "SCID".
  • The page is "page1".
  • And the subform is "supplement".

So to reference the subform you can just use this:

SCID.page1.supplement.presence = "hidden";

Because I see that the radio button exclusion group is on page1, then it is even simpler:

supplement.presence = "hidden";

Here you are using a relative reference from the radio button exclusion group to the subform.

Now to the last part, the if/else test is slightly incorrect. When testing against equality you need a double equal sign (==). So the full script would be:

if (this.rawValue == 0) {

     supplement.presence = "visible";

}

else {

     supplement.presence = "hidden";

}

I would put this in the click event of the radio button exclusion group and just run it at client.

Hope that helps,

Niall

Avatar

Level 2

Thank you. I realized a little while after that I didn't need the resolve node, but you'er response shortened up what I had even more. Now it's great that supplement shows up when the radiobutton equal to 0 is clicked, but it still does not go away if 0 is no longer clicked. I tried changing it from a radio button to a check box. The issue there is that I click the check box and supplement permanently appears, but the check in the box instantly goes away. Suggestions on how to get supplement to return to being hidden if the radio button or check box is not selected? I tried applying the same code to the click event on a drop down list. Here supplement becomes visible only after a.) the drop down list selects the appropriate value AND b.) the drop down box is clicked again. However, if I change the value to make the statement false (and click the drop down box a second time), supplement becomes hidden again. Any suggestion why the box may need to be clicked twice for the script to execute correctly?

Avatar

Level 10

Hi,

When dealing with radio buttons it is better to place the script in the click event of the exclusion group. In the hierarchy, the exclusion group contains all of the individual radio buttons.

So select the exclusion group in the hierarchy. In your previous post this was called KSCP_001. Then place the script in the click event.

If you are sticking with the dropdown, use the exit event, as your script is using the .rawValue and this will be committed by the time the exit event fires.

Hope that helps,

Niall