Expand my Community achievements bar.

How do I use JS to set values for their corresponding dropdown labels?

Avatar

Level 2

I want to loop through an array of 2-element arrays to populate a dropdown list.

Each item in this dropdown list should have a "label" and a corresponding "value" (like the "value" attribute is to the <option></option> tagsn in HTML).

In my top-level script object I have the following:

//////////////////////////////////////////

// BEGIN: BUILD COMMERCIAL PRODUCT LIST //

//////////////////////////////////////////

var

commercialProductList=new Array(

new

Array("Sydney Cityscope - Online","sydney_cityscope_online"),

new

Array("Sydney Cityscope - Hard Copy","sydney_cityscope_hardcopy"),

new

Array("Sydney Lease Expiry Diary","sydney_leaseexpirydiary"),

new

Array("North Sydney Cityscope - Online","northsydney_cityscope_online"),

new

Array("North Sydney Cityscope - Hard Copy","northsydney_cityscope_hardcopy"),

new

Array("North Sydney Lease Expiry Diary","northsydney_leaseexpirydiary"),

new

Array("South Sydney Cityscope - Online","southsydney_cityscope_online"),

new

Array("South Sydney Cityscope - Hard Copy","southsydney_cityscope_hardcopy"),

new

Array("South Sydney Lease Expiry Diary","southsydney_leaseexpirydiary")

);

////////////////////////////////////////

// END: BUILD COMMERCIAL PRODUCT LIST //

////////////////////////////////////////

In my form item initialization I have the following:

----- form1.#subform[0].Item1Product::initialize: - (JavaScript, client) ---------------------------

Item1Product.clearItems();

for

(var i = 0; i < sco.commercialProductList.length; i++)

{

Item1Product.addItem(sco.commercialProductList[i][0]

,sco.commercialProductList[i][1]);

}

My tex field to show the result has:

----- form1.#subform[0].Item2Product::change: - (JavaScript, client) -------------------------------

Item2QuantityType.rawValue

= Item2Product.value;

However, when I run the PDF, the dropdown puts something like this in the textfield...

Object91268092

Can anybody show me where I am going wrong?

Thanks! 

Stanbridge

3 Replies

Avatar

Level 2

Ah, nevermind.  Got it...

----- form1.#subform[0].Item2Product::change: - (FormCalc, client) ---------------------------------

Item2QuantityType.rawValue

= Item2Product.rawValue;

That works.

Now, if I can just figure out a way to make it update the text immediately on selection change INCLUDING the first selection I make!

(At present, I have to select something, then select something else to get the corresponding text field to update!)

Avatar

Former Community Member

The rawValue property does not get set until you exit the DDList. If you want to use the change event then you shoudl use xfa.event.newText to get what the user selected.

Paul

Avatar

Level 2

Hi Paul,

Thanks for the reply.  Yep, I googled that solution which somebody else had mentioned in another forum.  So sounds like it could be what most people do.

That said, I just moved my setting of the text field to the Exit event and it all worked, see below....

----- form1.#subform[0].Item2Product::exit: - (FormCalc, client) -----------------------------------

Item2QuantityType.rawValue = this.rawValue;

Works good enough for me!

Thanks anyway though mate.  Good to have another solution on standby should mine fall arse over!

Cheers,

Stanbridge