Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

How do you make a checkbox hidden or visible based on choices in a dropdown list?

Avatar

Former Community Member

I'm working on a quote request form.  In a DropdDown List I have the following mail classes as values:

     First Class

     Periodical Non-Profit

     Periodical Regular

     Standard Non-Profit

     Standard Periodical

I also have a CheckBox with the caption:Mailing List Provided.

I want to make it so that if a user selects Periodical Non-Profit or Periodical Regular from the DropDown List -- the CheckCox becomes visible (because a Mailing List is requried for these choices).  And if the user makes the other selections, I want the CheckBox to be invisible.  This seems easy enough to do but what script should I use?

12 Replies

Avatar

Level 10

Hi,

If you select the dropdown, go to the Object > Binding palette. There tick specify values and go with 1 to 5. This will make it easier to script.

Then in the exit event of the dropdown, use the following JavaScript:

if (this.rawValue == 2 || this.rawValue == 3) {

     Checkbox.presence = "visible";

}

else {

     Checkbox.rawValue = 0; // Clear the checkbox

     Checkbox.presence = "invisible";

}

You would need to use the name of your checkbox.

Hope that helps,

Niall

Avatar

Former Community Member

Thanks, Niall. This looks totally logical but nothing happens when I apply the script. Is there something more to this?

Avatar

Level 10

Hi,

Make sure the form is saved as a Dynamic XML Form in the Save-As dialog. Also, you have to change "Checkbox" to the actual relative reference to the checkbox on your form.

In the exit event, make sure the language is set to JavaScript.

If that is not working open the JavaScript Console (Control+J) and see if there are any errors showing up there.

Niall

Avatar

Former Community Member

Awesome! Saving the form as a Dynamic XML Form was what I was missing. I had the language set as Javascript and actually named the Checkbox to be “Checkbox” so those weren’t a problem.

One more question – is there a way to make the Checkbox invisible when is the default? In other words, can it be invisible when you open the form unless you select one of the options that makes it visible?

Avatar

Level 10

Yes, at design time in LC Designer, select the checkbox and in the Object > Field palette go to the Presence dropdown and select Invisible.

Niall

Avatar

Former Community Member

Nice! That worked beautifully. Thanks very much for your time today.

Avatar

Former Community Member

Niall,

I have 8 check boxes (4 of them are "yes" check boxes) and (4 of them are "no"check boxes) when i select a yes check box I have a javascript code in LiveCycle that changes the presence of a text box to "visiable" (the text box was set manually to invisable) then it highlights the field in the color pink.  Now when I select the no check boxes it changes the presence of the text field to "invisable" and not highlight show.( which is what I want)  When I select all the "yes" check boxes the code works as it should,  when I deselect random 'yes" check boxes and switch them to "no" check boxes and I still have one selected "yes" check box the text box changes its presence to "invisiable.  But I still have one yes check box selected and I want the field to stay highlighted and presence visiable.  If I deselect all yes boxes then the textr field highlight should come off and the presence goes to invisable. Any reason why this is not happening?

Thanks

Jagan

Avatar

Former Community Member

Thank you for your email. I will be out of the office Monday June 11 through Tuesday June 19.

Avatar

Level 10

Hi Jagan,

It is probablly just how you set up the script.

For starters, for Yes/No choices I think you would be better to use radio buttons instead of checkbox objects. So for example you would have four different radio button exclusion groups, each with a Yes and No radio button. Then in the Object > Binding palette, you would set the Yes value to 1 and the No value to 0.

This way you can sum the four radio button exclusion groups and if the total value is >=1 then change the presence of the text field and highlighting to suit.

There are some examples here that might help:

Scoring options: http://assure.ly/uiKS6f.

Tracking interaction (checkboxes): http://assure.ly/xDbtbx.

Hope that helps,

Niall

Avatar

Former Community Member

Thank you for your email. I will be out of the office Monday June 11 through Tuesday June 19.

Avatar

Former Community Member

Thank you for your email. I will be out of the office Monday June 11 through Tuesday June 19.