These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to get the Value item of the Drop-down list with JavaScript

abrob
Registered: Aug 15 2010
Posts: 8

HI
 
I have a drop-down list displaying for instance Apple, Orange, Banana. But I don't want to have the text value displayed when selected but the item value
 
Value | Text
1 Apple
2 Orange
3 Banana
  
And you pick Apple I would like to get 1 displayed or as return value.
 
Any idea with JavaScript?

Abrob

My Product Information:
LiveCycle Designer, Windows
Bamboolian
Registered: Jul 27 2010
Posts: 48
Hi,

To get value of dropdown or listbox, it will depends on in which event your script is going to be written.

If you're tring to get the value in dropdown field's own event like change, you'll need to refer to xfa.event.newText for new text changed by user and use it to get the value by using boundItem method.

var myDDNewValue = this.boundItem(xfa.event.newText);
When you need to get the value of dropdown in other field's event, then you'll only need to refer to rawValue of the dropdown object.

var myDDValue = DropDownList.rawValue
abrob
Registered: Aug 15 2010
Posts: 8
I put this var myDDNewValue = this.boundItem(xfa.event.newText); in the Change event but unfortunately I didn't get the the value of my drop-down list 1, 2, 3 BUT GET STILL THE TEXT VALUE Apple, Orange and Banana.

Thanks

Abrob

Bamboolian
Registered: Jul 27 2010
Posts: 48
Hi,

OK, this is what I used to test last week.

dropdown - change
xfa.host.messageBox ("this.boundItem(xfa.event.newText) : " + this.boundItem(xfa.event.newText) + "\n" +"xfa.event.newText : " + xfa.event.newText);
place it in change event of the dropdown, and if it doesn't work, then I guess I have to leave this topic to somebody else.


button - click
xfa.host.messageBox("DropDownList1.rawValue : " + DropDownList1.rawValue + "\n" +"DropDownList1.getDisplayItem(DropDownList1.selectedIndex) : " + DropDownList1.getDisplayItem(DropDownList1.selectedIndex));
abrob
Registered: Aug 15 2010
Posts: 8
Thanks for your help.....I put an hidden filed on the top of the DD list.When I choose an entry from the DD, the DD turn hidden and the hidden field became visible and display the value of the item selected in the DD...Thanks again , because of your replies I got the idea.....

Abrob