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 to assign a variable to a dropdown list value

Avatar

Level 2

I have developed a list of variable that are actually peoples names. The value I assigned to each is their contact information. When their name is selected from a dropdownlist, I would like their contact info to appear in a text field below the dropdown list box.

Does anyone have a sample of how to do this or insight on this.

Thanks in advance,

Paul

7 Replies

Avatar

Former Community Member

I have a form with a drop-down list called 'dropDown' and a text field called 'textField'. On the drop-down change event call the calculate event on 'textField' as follows:

// form1.page1.subform1.dropDown::change - (JavaScript, client)

form1.page1.subform1.textField.execEvent("calculate");

On the text field calculate event add the script below.

// form1.page1.subform1.textField::calculate - (JavaScript, client)

this.rawValue = xfa.event.newText;

Steve

Avatar

Level 7

If you have multiple contacts, a switch statement might be a good choice. In this example, I used nameList for the drop down list containing the names and text as the name of the field being populated with contact info.

switch

(nameList.rawValue)

{

case "John Smith":

text.rawValue

= "32 West Lane Some City Some Zip Code";

break;

case "Joe Brown":

text.rawValue

= "33 West Lane Some City Some Zip Code";

break;

case "Bill Jones":

text.rawValue

= "34 West Lane Some City Some Zip Code";

break;

default:

}

Avatar

Level 2

How does this call the variable set

in the form properties

under the variable tab?

Thanks

Paul

Avatar

Level 7

The same way you would call them for the drop-down list; maybe I misunderstood, are you not already populating the drop-down list with your variables?

Avatar

Level 7

For your drop-down list, let's say you have a global variable called pf with a value of PFrigo1. In your drop-down list on the initialize event you would script:

dropdownlist1.addItem(pf.value);

Avatar

Level 2

The choices listed in the drop down list have values set through the form properties. Please see the screen shot:

When you select the persons name from the drop down, the text field will populate with the value defined for that particular variable.

I hope this makes sense.

Variables.jpg

Avatar

Level 7

Ok, so the drop-down list has a list of names in it already, right? In that case you could try this:

switch(nameList.rawValue)

{
case "John Smith":
text.rawValue= John.value;
break;
case "Paul Brown":
text.rawValue= Paul.value;
break;
default:
}

The reference for the global variables is variablename.value.