Expand my Community achievements bar.

SOLVED

drop down list values question

Avatar

Level 3

I have successfully created a repeatable subform that calculates total fields. But to make the repeatable subform more user friendly and to make the form itself neater, I want to insert a dropdown list into that repeatable subform. But in order to do that and have the calculations work right, the selections in the drop down list would have to have number values (that are not visible or course). For example if it were a shopping list that had the item milk, I would want a dollar value assigned to the milk. So I guess my question is, can I add items to a drop down list using javascript alone and assign values to those items at the same time, or would I have to have the list print the value number to a hidden text field in order to use it in a calculation script. Or would I have to do a data connection from excel? Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can have the Display text and the value associated with it at the same time using scripts.

DropDownList1.addItem("milk", "2.90");

In the above, addItem method accepts 2 parameters. First one Display text and the second one as the value.

If the user selects milk from the dropdown, then the "DropDownList1.rawValue" property will give value as "2.90"..

Hope this helps.

Thanks

Srini

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

You can have the Display text and the value associated with it at the same time using scripts.

DropDownList1.addItem("milk", "2.90");

In the above, addItem method accepts 2 parameters. First one Display text and the second one as the value.

If the user selects milk from the dropdown, then the "DropDownList1.rawValue" property will give value as "2.90"..

Hope this helps.

Thanks

Srini

Avatar

Level 3

Thanks... That was easier then I thought it would be

Avatar

Level 7

I would like to add 2 things to consider.

Choosing the event for your dropdown box to populate is important. One powerful event to consider is the preOpen event that is available to dropdown boxes. This event doesn't take place until the user clicks on the dropdown list tab. This allows you to populate the dropdown list using values currently occupying other fields or using those values as indexes to other fields or as a factor in calculations where the results might be used in populating your dropdown box.

This is something I wish I had known prior to some of my earlier forms, where I used the initialize event to script the populating of dropdown boxes. Using the initialize event means only one fixed array/set of choices can populate the dropdown box. Using the preOpen event means the dropdown box can have differnt choices depending upon the user's interactions with the form prior to clicking on it.

Finally, put the actions/calculations you want to occur as a result of the user choosing an option in your dropdown box, on the "exit" event of the dropdown. This event uses the "rawValue" (the unseen value) of the box.You might not get the results you were expecting using a different event.

Good luck,

Stephen

Avatar

Level 3

okay only one problem with that. Each instance of the repeatable subform does not contain the script. When I add just three lines to the table I can easily select one of the items from the dropdown list in "only" the first row on the table. In the second and third row the dropdown list does not have any selections available. So how do I reference the script to work on each row?

Avatar

Level 3

Stephen that worked!!! Thanks. I was trying to put the script in the DocReady Event. Thanks for the advice, its appreciated a lot!

Avatar

Level 10

Nice find Stephen, hadn't realised what that event was for before. Opens up a bunch of possibilities!