Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Drop Down List Item Values

Avatar

Former Community Member
I have a drop down list set up. On the binding tab I selected the item value box and set an item value for each item in the drop down list.



How do i reference that item value in a script? I know xfa.event.newText will reference the item as seen in the drop down list, but I need the item value I gave each item in the binding tab.



Thanks for the help.
6 Replies

Avatar

Former Community Member
You can use the command:



DropDownList1.getDisplayItem(Index)



where Index is the index of the selected value. To get that you can use:



DropDownList1.selectedIndex



So your final command would look like:



DropDownList1.getDisplayItem(DropDownList1.selectIndex)



Hope that helps

Avatar

Former Community Member
Thank you for the reply. The command is not working, though. It is displaying the same thing that xfa.event.newText displays, although it is one selection behind. So, it isn't even displaying the current selection info it is displaying the previous selection's info.



I'll give more info to see if it helps:



Let's say that I have the following items in my drop down list;



Some Guy

Another Guy

Different Guy

The Guy



If you go to the binding's tab on the drop down list there is a check box next to "Specify Item Values" when you check that you get some new options.



By default each item is numbered like:



1 Some Guy

2 Another Guy

3 Different Guy

4 The Guy



You can change the numbers to custom values like:



SG Some Guy

AG Another Guy

DG Different Guy

TG The Guy



What I want is a command to give me SG, AG, DG or TG when it's respective value is selected in the drop down. I hope this helps.



Thanks again

Avatar

Level 4
I do this by running through my bound data and scanning for the xfa.event.newText value, then getting the key (this is on dropdown change event).<br /><br />> var oItems = xfa.resolveNode("xfa.record.FormData.ListData");<br /><br />> var nItemsLength = oItems.nodes.length;<br /><br />> for (var nItemCount = 1; nItemCount < nItemsLength; nItemCount++) {<br /><br />> if (oItems.nodes.item(nItemCount).uiname.value==xfa.event.newText) {<br /><br />> xfa.host.messageBox("your value: "+oItems.nodes.item(nItemCount).token.value);<br /><br />> }<br /><br />>}<br /><br />Here's a snip of sort of XML data used to binding the drop down label and value in my version:<br /><br />> <ListData><br /><br />> <ListItems uiname="This text is" token="001"/><br /><br />> <ListItems uiname="Displayed in dropdown" token="002"/><br /><br />> <ListItems uiname="but the token is stored in data" token="003"/><br /><br />> </ListData><br /><br /> <br />You'll have to match up the code above to the locations of your binding in your schema, and if anyone knows an easier way I'd love to hear it. ;)<br /><br />I've hastily pulled this out of an form that uses this in a chain of multiple label/value bound drop downs, so apologies if I've made any errors in simplification.

Avatar

Former Community Member
I do mine on the exit event of the dropdown (after the choice has been comitted).

If you try my single line of code on that it will work.

Avatar

Level 4
It doesn't work, it just gives the label. While I was testing that I stumbled across a one liner which does work, and I wish I'd found earlier!



In the change event:



> DropDownList1.boundItem(xfa.event.newText);