Expand my Community achievements bar.

SOLVED

Select dropdown value using script

Avatar

Level 9

How do I select the boundItem of a dropdown object list based on the rawValue of another field?

So if the rawValue of TextField1 = 1641

how do I select the boundItem 1641 value of my dropdown using script?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I think you'll have to loop though the bound values, like;

for (var i = 0; i < DropDownList1.length; i++) {

    if (DropDownList1.getSaveItem(i) == "1641) {

        DropDownList1.selectedIndex = i;

    }

}

Regards

Bruce

View solution in original post

11 Replies

Avatar

Correct answer by
Level 10

Hi,

I think you'll have to loop though the bound values, like;

for (var i = 0; i < DropDownList1.length; i++) {

    if (DropDownList1.getSaveItem(i) == "1641) {

        DropDownList1.selectedIndex = i;

    }

}

Regards

Bruce

Avatar

Level 9

Bruce,

Thanks for your reply. unfortunately, I cannot get it to work. I created an example form and linked it below if you would be willing to take a look at it. Thanks for your help.

- Don

Shared Files - Acrobat.com

Avatar

Level 10

Hi there,

If you ensure that you input data appropriately into the drop down field it can be really easy.

If you input data in the drop down list with the following :

you can easily select the value 2 by using the rawValue of the drop down field, this way :

This way the value of the drop down list should be "More Text"..

Hope this will help!

Avatar

Level 9

Magus069,

Thanks for your reply. I am not able to input my dropdown object data. It is a long list of employee numbers copied and pasted into the form. The binding side is a concatenate text field that populates the employee name field and contains other data like their email address.

My form is connected to a database. I need to click a button the form with a script that finds an employee number in the database record and then selects that employee number in the dropdown field the same as if a user selected the employee number from the list in that dropdown. Doing so will run the script that is attached to the exit event of the employee number field.

It's involved why I need to do this so I won't explain it all at this time. I need script that will search for an employee number (for example employee number 1649) and selects that number when it finds it in the list - the same as if the user selected from the dropdown list.

Thank you

Avatar

Level 10

You shouldn't complicate things for the binding side.. you should only bind the ID of the employee and wherever you go in the form only use ID to access any record from the database... If you input data to your drop down list from the database, you should bind the ID of the employees instead of concatenated fields.

Avatar

Level 9

Yes, I realize that now. I'm still learning LiveCycle (the hard way!)

I am able to get the employee number in the dropdown. Is there a way to run the exit event with script after I populate the formattedValue of the dropdown field?

Avatar

Level 10

Not quite sure what you are asking...

You are suppose to be able to fire the exit event of the drop down list when there is script in it.

Avatar

Level 9

Sorry, I am not being clear.

I can use script to get the value from the database and put it into the dropdown but that does not seem to run the exit event script. Is there script that I can add that will run the exit event after I populate the dropdown?

Maybe this isn't possible since I am not selecting from the dropdown list but rather just entering a formattedValue.

Avatar

Level 10

You can execute any event script at any time by using the method execEvent() like the following

Avatar

Level 9

I would have to recreate the entire form to pull data from the database to each of the fields necessary. I agree that is how the form should have been created but for now I need to make this work the way it is.

So my question remains, using script, I am trying to select a particular number from the dropdown list and have the dropdown exit event run so the script in the dropdown object runs the same way it would run if a user select the number from the list themselves.

I have tried script that puts the rawValue in the dropdown and then script to run the exit event

dropdown1.execEvent("exit");

to run the exit event but it does not run the script.

then I tried script that adds the formattedValue in the dropdown but that does not work either.

Is there a way to loop thru the dropdown list and select the index to simulate a user selecting from the list like Bruce suggested? His script using selectedIndex does not seem to be available in LiveCycle forms.

Avatar

Level 9

Had to change getSaveItem to getDisplayItem and your script works.

Thank you Bruce.