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.
SOLVED

passing selected value from one dropdown list to another

Avatar

Level 2

Hi,

I have two lists and I wanted to make sure that people select from the first drop down list before selecting from the second drop down list. So what I tried to do was, if the user tries to pick something from the second list and the first list was not selected, an error message will pop up to ask user to select from the first list.

The problem that I encountered: I cannot pass the value from the first list to the second list to check and see if the first list has got anything selected. Any idea?

First list: department

second list: jobs

in the first drop down list

var selected = xfa.event.newText;

second drop down list

if(selected==""||selected=="null"){

xfa.host.messageBox("Please select from the first drop down list before selecting from this list.");

}

Thanks,

F.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

In the first dropdown script you declare a variable "selected". This form variable only lives within that event. You cannot accessthat variable from other events or from other objects.

You are on the right track, but instead of testing the variable in the if statement, test the rawValue of the first dropdown.

if (dropdown1.rawValue == null || dropdown1.rawValue == "")

{

     xfa.host.messageBox(...);

     xfa.host.setFocus("xfa.form.form1.page2.dropdown1");

}

Hope that helps,

Niall

View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

Hi,

In the first dropdown script you declare a variable "selected". This form variable only lives within that event. You cannot accessthat variable from other events or from other objects.

You are on the right track, but instead of testing the variable in the if statement, test the rawValue of the first dropdown.

if (dropdown1.rawValue == null || dropdown1.rawValue == "")

{

     xfa.host.messageBox(...);

     xfa.host.setFocus("xfa.form.form1.page2.dropdown1");

}

Hope that helps,

Niall

Avatar

Level 9

Hi,

In the click event of the 2nd DropDown you can write the following script.

if (DropDownList1.rawValue == null)

     {

          xfa.host.messageBox("Please select from the first drop down list before selecting from this list.");

     }

Generally null is not written within double quotes.

One more suggestion would be make the 2nd DropDown readOnly. In the Change event of the first dropDown make it not readOnly.

Thanks,

Bibhu.

Avatar

Level 9

Sorry Niall, Concurrent action again.

Bibhu.

Avatar

Level 2

Hi Niall,

It worked! Thanks for pointing that out! I understand now. Presume that they are considered as local variables unless we set them to global.

Thanks heaps!

Regards,

Florian

Avatar

Level 2

Hi Bibhu,

Thanks for your suggestion. That's a good idea too! I shall try that too and see if it works.

Regards,

Florian

Avatar

Level 10

Hi Florian,

You could use global variables, but in this case you don't really need them.

When using global variables, you would declare them in File > Form Properties > Variables. To read or write variables in script you would use the .value: eg globalVariableName.value.

[No worries Bibhu ]

Niall

Avatar

Level 2

Hi Niall,

OK, thanks again.

Regards,

F.