Expand my Community achievements bar.

SOLVED

How to auto populate a field based on drop down list unless specific item is selected

Avatar

Level 1

Hi all,

Apologies if I have posted this in the wrong area but I am new to Adobe LiveCycle, JavaScript and these forums.

I am trying to build an Acrobat form using LiveCycle but am having trouble with the drop down lists.

Inititaly I simply wanted to populate fields in one table based on the selection of a corresponding drop down list in another table.

I used the following code and it worked fine:

 

Workbook.Content.Table1.Row3.AppropriationDetails.Row4.Cell1::change - (JavaScript, client)

var fFrom = xfa.resolveNodes("Workbook.Content.Table1.Row3.AppropriationDetails[*].Row4.Cell1");

var fTo = xfa.resolveNodes("Workbook.Content.Table2.Row3.AppropriationDetails[*].Row4.Cell1");

for (var i=0; i <= fFrom.length-1; i++) {

     fTo.item(i).rawValue = fFrom.item(i).boundItem(xfa.event.newText);

}

The problem is that now I want the above code to work UNLESS one of the items in the dropdown list is specifically selected in which case I want the text box in the other table to display a message such as "Enter details in the field below".

I have tried to create an If Else statement using the following code:

Workbook.Content.Table1.Row3.AppropriationDetails.Row4.Cell1::change - (JavaScript, client)

var fFrom = xfa.resolveNodes("Workbook.Content.Table1.Row3.AppropriationDetails[*].Row4.Cell1");

var fTo = xfa.resolveNodes("Workbook.Content.Table2.Row3.AppropriationDetails[*].Row4.Cell1");

for (var i=0; i <= fFrom.length-1; i++) {

     if (fFrom.item(i).rawvalue = "Option 3"){

     fTo.item(i).rawValue = "Enter details in the field below";

     }

     else {

     fTo.item(i).rawValue = fFrom.item(i).boundItem(xfa.event.newText);

}

}

The code now populates the field with "Enter the details in the field below" no matter what item I select from the dropdown list.

Your help is greatly appreciated.

Cheers,

ozzy_q

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You are using .rawValue in the change event. This will cause problems because the users selection has not been assigned to the dropdown's .rawValue by the time the change event fires.

Move your script as it is to the exit event of the dropdown.

Hope that helps,

Niall

View solution in original post

3 Replies

Avatar

Level 1

Follow Up:

Ok so ive changed things up a bit and have had some more success.

I have used a Switch statement in my For loop to perform different actions based on the item selected.

The code looks like this:

  

 

Workbook.Content.Table1.Row3.AppropriationDetails.Row4.Cell1::change - (JavaScript, client)

var fFrom = xfa.resolveNodes("Workbook.Content.Table1.Row3.AppropriationDetails[*] .Row4.Cell1");

var fTo = xfa.resolveNodes("Workbook.Content.Table2.Row3.AppropriationDetails[* ].Row4.Cell1");

 

for (var i=0; i <= fFrom.length-1; i++) {

     switch (fFrom.item(i).rawValue)

{

     case "Option 3":

     fTo.item(i).rawValue = "Enter the details in the field below";

     break;

     default:

     fTo.item(i).rawValue = fFrom.item(i).boundItem(xfa.event.newText);

     break;

}

}

This code solves my problem but has thrown up a new issue:

When i select Option 1 or 2 from the dropdown list  the change in the text field is instantaneous, however if I select Option 3 it wont appear in the text field until I either select Option 3 a second time or select another item. Its as if the text field is a selction behind what I have enterd in the dropdown list.

Any thoughts?

Avatar

Correct answer by
Level 10

Hi,

You are using .rawValue in the change event. This will cause problems because the users selection has not been assigned to the dropdown's .rawValue by the time the change event fires.

Move your script as it is to the exit event of the dropdown.

Hope that helps,

Niall

Avatar

Level 1

Thanks heaps,

that worked - I basically changed the Swirch statement from:

switch (fFrom.item(i).rawValue)

to

switch (fFrom.item(i).boundItem(xfa.event.newText))

thanks again