Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Drop Down Boxes

Avatar

Former Community Member

Hello,

I have a drop down box with 5 options. When the user chooses one of the options a hidden form appears. Sometimes it doesnt appear right away, or you have to click somewhere on the form for the hidden form to appear. I don't understand what I'm doing wrong...I am using the following script:

under the change event:

if(this.rawValue == 1)

{one.presence = "visible";}

else

{one.presence = "hidden";}

if(this.rawValue == 2)

{two.presence = "visible";}

else

{two.presence = "hidden";}

(ive done this for all 5 options)

under the click AND exit events:

if(NumOfDep.rawValue == "1")

{one.presence = "visible";

one.surname.mandatory = "error";}

else

{one.presence = "hidden";

one.surname.mandatory = "disabled";

one.surname.rawValue ="";}

if(NumOfDep.rawValue == "1")

{two.presence = "visible";

two.surname.mandatory = "error";}

else

{two.presence = "hidden";

two.surname.mandatory = "disabled";

two.surname.rawValue ="";}

(ive done this for all 5 options)

Thank you!

5 Replies

Avatar

Level 10

Hi,

The change event needs xfa.event.newText instead of dropdowns, as the .rawValue hasn't been registered for the new selection by the time the change event fires.

I find with dropdowns the best event is the exit event and you would then use the 'this.rawValue' as you have it.

You should just have one set of script, as it seems you have doubled up on events to achieve the same thing. I would recommend a switch statement. First hide all of the subforms and then make the appropriate one visible. So in the exit event of the dropdown:

// hide subforms

one.presence = "hidden";

two.presence = "hidden";

three.presence = "hidden";

four.presence = "hidden";

five.presence = "hidden";

// switch statement

switch (this.rawValue)

{

     case "1":

     one.presence = "visible";

     break;

     case "2":

     two.presence = "visible";

     break;

     case "3":

     three.presence = "visible";

     break;

     case "4":

     four.presence = "visible";

     break;

     case "5":

     five.presence = "visible";

     break;

}

You can also include the mandatory script as well.

Hope that helps,

Niall

Avatar

Former Community Member

If you could forward the form to stwalker.adobe@gmail.com I would be happy to take a look.

Steve

Avatar

Level 10

You need to use this.boundItem(xfa.event.newText) to capture the selected value in the dropdown.

Like this (on the change event):

var selection = this.boundItem(xfa.event.newText);

if (selection == 1)

{one.presence = "visible";}

else

{one.presence = "hidden";}

if (selection == 2)

{two.presence = "visible";}

else

{two.presence = "hidden";}

If you're doing a lot of these I find it easier to use a switch() statement:

var selection = this.boundItem(xfa.event.newText);

switch(selection)

{

     case "1":

          one.presence = "visible";

          two.presence = "hidden";

          break;

     case "2":

          one.presence = "hidden";

          two.presence = "visible";

          break;

     default:

          // put any default code you want to fire here

}

Avatar

Level 10

It's like busses - you wait for ages for one and then three come along together